Skip to content

Instantly share code, notes, and snippets.

@shrimo
Last active April 30, 2020 12:01
Show Gist options
  • Save shrimo/300127f3bb6cce6c6b330b43d26a98dd to your computer and use it in GitHub Desktop.
Save shrimo/300127f3bb6cce6c6b330b43d26a98dd to your computer and use it in GitHub Desktop.
# nuke channal ranamer
import os
import nuke
def renamer(old_line, new_line):
input_file = nuke.root().knob('name').value() # read nuke script path
if not os.path.isfile(input_file): # checking file availability
print 'no file', input_file
return
with open(input_file, 'r') as f: # Open file for reading
data = f.readlines() #Read data from file to list
filename, file_extension = os.path.splitext(input_file) # Separate file name and its extension
output_file = filename + '_new' + file_extension # create a new file name
print 'input file: ', input_file
print 'output file: ', output_file
f_write = open(output_file, 'w') # Open file for writing
for line in data:
if old_line in line: # If we find the old line in string
f_write.write(line.replace(old_line, new_line)) #change old to new and write
continue
f_write.write(line) # writing unchanged
f_write.close()
print '\nrename done'
old_line = nuke.getInput('Old line', 'ld01')
new_line = nuke.getInput('New line', 'ld02')
if new_line and old_line:
renamer(old_line, new_line)
else:
print 'Enter values in the fields'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment