Skip to content

Instantly share code, notes, and snippets.

@kpprt
Last active September 3, 2017 17:29
Show Gist options
  • Save kpprt/8c3b4e6724ab86e93a2f to your computer and use it in GitHub Desktop.
Save kpprt/8c3b4e6724ab86e93a2f to your computer and use it in GitHub Desktop.
Make all file references relative in a Nuke script when they start with the project directory (case-sensitive)
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
undo = nuke.Undo()
undo.begin("make file paths relative")
project_dir = nuke.Root()['project_directory'].value()
if not project_dir.endswith('/'):
project_dir += '/'
for n in nuke.allNodes():
k = n.knob('file')
if k != None:
current_path = k.value()
relative_path = remove_prefix(current_path, project_dir)
k.setValue(relative_path)
undo.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment