Q100491: Automatically localizing files from multiple paths
Warning: This article contains links to external websites
SUMMARY
This article outlines how you can automatically localize files from multiple different paths as, currently, Nuke’s 'auto-localize from' feature only allows localization from one path by default.
MORE INFORMATION
Nuke
You can automatically localize files from multiple locations in Nuke by writing a Python script, which you then add to your init.py file. The example code below will localize files that are stored within either of the following file paths: /first/localization/path/ or /second/localization/path/
import nuke
localizationDrives = ('/first/localization/path/', '/second/localization/path/') #add paths you want to localise from to this list
def automaticLocalization():
for i in nuke.allNodes():
nodeClass = i.Class()
if nodeClass == 'Read' and (i.knob('file').value().startswith(localizationDrives)):
i.knob('localizationPolicy').setValue('on')
nuke.addOnCreate(automaticLocalization)
The code works by first creating a list of directories to localize from, then the function, called ‘automaticLocalization’, is defined. Inside the function, the code loops through all of nodes in the Node Graph and checks for the following criteria:
- That the node is a Read node
- And that the node’s ‘file’ knob has a value that starts with either /first/localization/path/ or /second/localization/path/
If both criteria are met, the Localization Policy for that node is set to ‘on’. The addOnCreate callback is then used to call the ‘automaticLocalization’ function whenever a node is created in the node graph.
Hiero
You can also write a similar script for Nuke Studio and Hiero, however, this code would need to be added to your ~/.nuke/Python/Startup directory. Like the above example, the following code below will localize files that are stored under either of the following file paths: /first/localization/path/ or /second/localization/path/
import hiero
import nuke
localizationDrives = ('/first/localization/path/', '/second/localization/path/') #add paths you want to localise from to this list
def hieroLocalize():
for proj in hiero.core.projects():
for Clips in proj.clips():
if Clips.readNode()['file'].value().startswith(localizationDrives):
try:
Clips.readNode()['localizationPolicy'].setValue('on')
except:
pass
nuke.addOnCreate(hieroLocalize)
Much of the logic of this code is the same as the Nuke code above and the major difference is how the clips are accessed in the Hiero Bin, rather than in Nuke’s Node Graph. The Hiero code works by first looping through all of the projects, and then all of the clips, this will then return all clips in the Bin then, similar to the above Nuke code, it then checks whether the ‘File’ knob has a value that starts with either /first/localization/path/ or /second/localization/path/. The same addOnCreate callback is used to run the localization code whenever a clip is imported into the Bin or when a project is loaded.
Nuke Studio
From our testing, it appears that both of the above methods work on Nuke Studio’s Timeline but only the ‘Nuke’ method will work in the Node Graph. You should incorporate this into your setup to best suit your current pipeline and workflow.
FURTHER READING
There is currently a feature request logged for allowing the 'auto-localize from' feature to accept multiple paths. The reference number for this is the following:
TP 147811 - Add the ability to Auto Localise from multiple locations, not just one
You can reference this number in the release notes of upcoming versions of Nuke to see if it has been addressed.