Q100465: How to load plugins for different versions of Nuke

Warning:  This article contains links to external websites

SUMMARY

This article will outline two different methods for how you can load different plugin directories for multiple versions of Nuke.

This may be helpful if you are using multiple different versions of Nuke simultaneously as you may find that some third party plugins will not be compatible with all of the versions of Nuke that you are using.


MORE INFORMATION

Firstly, you will need to save your plugins in different directories for each Nuke version. You can then add the additional directories for Nuke to load upon launch.

Any plugins that you wish to load only for specific versions of Nuke should not be added into your local ~/.nuke folder as this directory is always loaded (unless you are running in safe mode).

There are two methods that you can use to load plugins for different versions of Nuke, the first is adding the plugin directories via Python by using the pluginAddPath() method, or the addPluginPath()method for Nuke Studio and Hiero. The second method is creating a custom wrapper script to launch Nuke, Nuke Studio or Hiero with an environment variable set.

The difference between the two methods is the evaluation order. Using the pluginAddPath() will add the directories to the front of Nuke’s plugin path whereas using an environment variable will load the directory after your ~/.nuke directory. The following is an example of running nuke.pluginPath() in the Script Editor with two directories added to Nuke’s plugin path, one added via Python and one set with an environment variable:

nuke.pluginPath()

# Result: ['/path/set/via/Python', 'C:/Users/username/.nuke', '/path/set/with/env/var', 'C:\\Program Files\\Common Files/Nuke/11.3/plugins', 'C:/Program Files/Nuke11.3v1/plugins/user', 'C:/Program Files/Nuke11.3v1/plugins/icons', 'C:/Program Files/Nuke11.3v1/plugins']

Which method you decide to use would depend on your current pipeline environment and any dependencies that your plugins may rely on.


PYTHON SCRIPT

Nuke

By using your init.py file, you can define what plugin path is loaded on launch for a given Nuke version.

Here is an example of the Python code that will check if you have launched Nuke 10 or Nuke 11 and load the plugin path accordingly:

import nuke

if str(nuke.NUKE_VERSION_MAJOR)=='10':
nuke.pluginAddPath("/path/to/plugins/folder/nuke11")

if str(nuke.NUKE_VERSION_MAJOR)=='11':
nuke.pluginAddPath("/path/to/plugins/folder/nuke10")


The above code will only check the major version of Nuke you are running (ie. Nuke 10, Nuke 11, etc.) but by using an ‘and’ statement and NUKE_MINOR_VERSION, you can be more specific with what Nuke versions will launch certain plugins. For example the following code will check if the Nuke version is 11.3, before loading the plugin path if the version matches:

if str(nuke.NUKE_VERSION_MAJOR)=='11' and str(nuke.NUKE_VERSION_MINOR)=="3":
nuke.pluginAddPath("/path/to/plugins/folder")


You can also check for the full Nuke version by using NUKE_VERSION_STRING, like so:

if str(nuke.NUKE_VERSION_STRING)=="11.3v1":
nuke.pluginAddPath("/path/to/plugins/folder")

Nuke Studio & Hiero

Similar to creating the plugin paths for Nuke, for Nuke Studio and Hiero you can do this by writing an ‘if’ statement that checks the version of Nuke Studio/Hiero that has been launched and will load the plugin paths accordingly.

However, rather than adding this code to your ~/.nuke/init.py file, it needs to be saved into a .py file inside of your ~/.nuke/Python/Startup or ~/.nuke/Python/StartupUI directories. You can find more information about adding plugin paths to Nuke Studio and Hiero here.

The following is an example for setting up different plugin paths to be loaded for Nuke Studio/Hiero 10 or 11:

import hiero
from hiero.core import *

if env["VersionMajor"]==10:
   hiero.core.addPluginPath("/path/to/plugins/folder/hiero10/Python/Startup")

if env["VersionMajor"]==11:
   hiero.core.addPluginPath("/path/to/plugins/folder/hiero11/Python/Startup")


Like with Nuke, you can use env["VersionMinor"] with an ‘and’ statement to define the plugin path for a major and minor version. For example, the following code will load the plugin path for all Nuke Studio/Hiero 11.3 versions:

import hiero
from hiero.core import *

if env["VersionMajor"]==11 and env["VersionMinor"]==3:
   hiero.core.addPluginPath("/path/to/plugins/folder/Python/Startup”)

You could also load the plugins based on the exact version by using env["VersionString"]:

import hiero
from hiero.core import *

if env["VersionString"]==11.3v1:
   hiero.core.addPluginPath("/path/to/plugins/folder/Python/Startup”)

CREATING A WRAPPER SCRIPT

A wrapper script embeds system commands or utilities into an executable file from which you can then repeatedly invoke the commands, without having to retype it in the command line. In this case, you can set the NUKE_PATH or HIERO_PLUGIN_PATH environment variable and launch the application. Setting the environment variable via a wrapper script means that the commands are only enabled for that active command line session and it is not permanently set on your system.

The wrapper scripts can be saved anywhere on your machine and can be executed by running them in the terminal. You could also set these files to be opened in the terminal by default so you can simply execute them by double clicking on it.

Nuke

The wrapper scripts for macOS and Linux contain very similar commands, with the Nuke application directory being the biggest difference between the two operating systems. Examples scripts for Nuke 11.3v1 on each operating system can be found below:

macOS

#! /bin/bash
export NUKE_PATH=/path/to/some/folder/
/Applications/Nuke11.3v1/Nuke11.3v1.app/Contents/MacOS/Nuke11.3v1

Linux

#! /bin/sh
export NUKE_PATH=/path/to/some/folder/
/usr/local/Nuke11.3v1/Nuke11.3

This is quite different from Windows, where you would need to create a script that runs the commands in the Windows Command Prompt. To do this, you can create a batch file (.bat) which contains the following commands:

Windows

set NUKE_PATH=/path/to/some/folder
"C:\Program Files\Nuke11.3v1\Nuke11.3.exe"

NOTE: You can also find example wrapper scripts for each OS attached to this article.

Nuke Studio & Hiero

For Nuke Studio and Hiero, you will need to set the HIERO_PLUGIN_PATH environment variable before launching the application, using either the -hiero or -studio launch flags.

macOS

#! /bin/bash
export HIERO_PLUGIN_PATH=/path/to/some/folder/
/Applications/Nuke11.3v1/Nuke11.3v1.app/Contents/MacOS/Nuke11.3v1 -studio

Linux

#! /bin/sh
export HIERO_PLUGIN_PATH=/path/to/some/folder/
/usr/local/Nuke11.3v1/Nuke11.3 -studio

Windows

set HIERO_PLUGIN_PATH=/path/to/some/folder
"C:\Program Files\Nuke11.3v1\Nuke11.3.exe" -studio

FURTHER READING

More information about loading plugins in Nuke can be found in the following pages of our documentation:

  1. Loading Gizmos, NDK Plug-ins, and Python and Tcl Scripts
  2. Defining the Nuke Plug-in Path
  3. Installing Plug-ins
  4. Nuke Python Reference Guide - NUKE_VERSION Variables
  5. Environment Info for Hiero
  6. Nuke Environment Variables

Attachments