Q100273: How to set path substitutions in a Nuke terminal session

Follow

SYMPTOMS

You have set up your path substitutions under Edit > Preferences... in Nuke, but the file paths aren’t substituted correctly during command line rendering or Python Terminal mode. Your path substitutions would look like:

 

CAUSE

File paths may not be substituted correctly on a command line render or Python Terminal mode because Preferences aren't loaded when Nuke is run outside of GUI mode.

Terminal mode (without GUI) allows you to enter Python commands without launching the GUI.
A >>> command prompt is displayed during this mode. Command line mode (batch mode) allows you to run commands in the terminal to render your Nuke script (without GUI). 
Please see the Nuke Online Help on Command Line Operations for more information.

 

RESOLUTION

To solve this, you can use the command line argument --remap, which will take a list of path substitution pairs and work only for the active Nuke session, or set a filenameFilter callback in your init.py file to have it persistent across all Nuke sessions.  

Current Nuke session

Here is an example of how the flag is used when running Nuke in Terminal Mode:

nuke -t --remap "X:/path,Y:,A:,B:/anotherpath"

Where:

  • nuke references the appropriate Nuke executable installation location: 

    Windows: C:\Program Files\Nuke15.1v1\Nuke15.1.exe
    OSX: /Applications/Nuke15.1v1/Nuke15.1v1.app/Contents/MacOS/Nuke15.1
    Linux: /usr/local/Nuke15.1v1/Nuke15.1

  • Any paths starting with X:/path are converted to start with Y:.
  • Any paths starting with A: are converted to start with B:/anotherpath.

To substitute paths between different operating systems, your command would look for example like:

nuke -t --remap "/home/project/shot/,C:/project/shot" 

NOTE: The path mappings are only applied to the current Nuke session and they do not affect the Preferences.nk file used when running the Nuke GUI.


Multiple Nuke sessions

To make your path substitutions persistent across multiple Nuke sessions you can use the filenameFilter callback. The following example shows how to set this up, for a similar scenario as the previous example:

import nuke

def myFilenameFilter(filename):
filename = filename.replace( 'X:/path', 'Y:/' )
filename = filename.replace( 'A:/', 'B:/anotherpath' )

return filename

nuke.addFilenameFilter(myFilenameFilter)

To execute this code in all terminal sessions, you will need to add the code to your init.py file.

More information about the filenameFilter callback can also be found in the Nuke Python Developer Guide

    We're sorry to hear that

    Please tell us why