It is only after joining trollbridge I realize how using project directory can make things easy in nuke, especially in a big script with lots of files. It makes transporting the folder significantly easier as you only need to change one path as you move the folder. If using relative file path in project directory and make sure all the files in script are set properly, you pretty much eliminate the process of relinking files. Which leads me to writing this script. This script allows users to set project directory with ease, converting file paths to relative file paths in the progress.
‘Set Project Directory’ will be added to the file menu and toolbar. If it’s a new script it’ll only show ‘Custom path’, which you can select a custom path for project directory. Note that this option will result in an absolute file path in your project directory knob.
Once you opened a script, other 5 options will shows up in both menus, which are going up 5 levels from the folder that contains your nukescript as shown in picture above. If you select one of these options your project directory will immediately set to that directory, which is using relative file path. So feel free to move your folder around after this is done. Choosing one of these options will also immediately alter all the file paths in your nukescript, changing them to relative file paths IF they are within your directory or sub-directory. If the file is in upper level of your directory, it will remain absolute. This works whether your file paths are already relative or absolute.
It also inlcuded additional scripts which are
- absFilePaths: Which will convert your selected nodes’ file paths (if has any) to absolute file paths, without affecting frame padding.
- selNodeWithFile: Select all the nodes with a file knob, this works extremely well with absFilePaths for me as sometimes I just want to make everything absolute for compatibility issue.
Writing this script I learned a lot about using nuke callbacks, especially when writing the function above, adding file paths relative to where the nuke script is located when a script is opened. I also realize that there are shortcuts to writing codes for nuke. For instance there are already a lot of pre-built functions hiding inside nuke python API module. Like I was attempting to write a function that create a list of nodes that contain a file knob, only to realize there’s already a function in nukescript.searchreplace module that does just that. Which I used extensively in this script.
This script is available for download on nukepedia here. In there you can find the short installation guide and any updates I’ll put up there!