Last active
September 3, 2017 17:29
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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