Q100465: How to load plug-ins for different versions of Nuke

Follow

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.

As of Nuke 13.0v1, Python 2 is no longer supported so this may also help while you are updating your Python scripts to be compatible with Python 3.7.

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 into the top level of 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:

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 which 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 13 or Nuke 15 and load the plugin path accordingly:

import nuke

if nuke.NUKE_VERSION_MAJOR==15:
nuke.pluginAddPath("/path/to/plugins/folder/nuke15")

if nuke.NUKE_VERSION_MAJOR==13:
nuke.pluginAddPath("/path/to/plugins/folder/nuke13")


The above code will only check the major version of Nuke you are running (ie. Nuke 13, Nuke 15, 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 15.1, before loading the plugin path if the version matches:

import nuke

if nuke.NUKE_VERSION_MAJOR==15 and nuke.NUKE_VERSION_MINOR==1:

nuke.pluginAddPath("/path/to/plugins/folder/nuke151")


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

import nuke

if nuke.NUKE_VERSION_STRING=="15.1v2":

nuke.pluginAddPath("/path/to/plugins/folder/nuke151v2")

 

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.

NOTE: The additional directories that you are loading will also need to contain the same /Python/Startup or /Python/StartupUI folder structure as your ~/.nuke folder.

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

import hiero
from hiero.core import env

if env["VersionMajor"]==15:
# scripts saved in /path/to/plugins/folder/hiero15/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero15")

if env["VersionMajor"]==13:
# scripts saved in /path/to/plugins/folder/hiero13/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero13")


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 15.1 versions:

import hiero
from hiero.core import env

if env["VersionMajor"]==15 and env["VersionMinor"]==1:
# scripts saved in /path/to/plugins/folder/hiero151/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero151")

You could also load the plugins based on the exact version by using env["VersionString"]. However, please note that the result of env["VersionString"] also includes the product name (for example "Hiero 15.1v2" or "NukeStudio 15.1v2"):

import hiero
from hiero.core import env

if env["VersionString"].endswith("15.1v2"):
# scripts saved in /path/to/plugins/folder/hiero151v2/Python/Startup
hiero.core.addPluginPath("/path/to/plugins/folder/hiero151v2")

 

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 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 15.1v2 on each operating system can be found below:

macOS

#! /bin/bash
export NUKE_PATH=/path/to/some/folder/
/Applications/Nuke15.1v2/Nuke15.1v2.app/Contents/MacOS/Nuke15.1

Linux

#! /bin/sh
export NUKE_PATH=/path/to/some/folder/
/usr/local/Nuke15.1v2/Nuke15.1

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\Nuke15.1v2\Nuke15.1.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/Nuke15.1v2/Nuke15.1v2.app/Contents/MacOS/Nuke15.1 --studio

Linux

#! /bin/sh
export HIERO_PLUGIN_PATH=/path/to/some/folder/
/usr/local/Nuke15.1v2/Nuke15.1 --studio

Windows

set HIERO_PLUGIN_PATH=\path\to\some\folder
"C:\Program Files\Nuke15.1v2\Nuke15.1.exe" --studio

  

FURTHER READING

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

  1. Q100490: What are the init.py and menu.py startup script files
  2. Loading Gizmos, NDK Plug-ins, and Python and Tcl Scripts
  3. Defining the Nuke Plug-in Path
  4. Installing Plug-ins
  5. Environment Info for Hiero
  6. Nuke Environment Variables

 

We're sorry to hear that

Please tell us why