Skip to content

Instantly share code, notes, and snippets.

@dbr
Created December 18, 2013 02:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbr/8016555 to your computer and use it in GitHub Desktop.
Save dbr/8016555 to your computer and use it in GitHub Desktop.
Get all files referenced by a Nuke file knob
def _collect_file_knob(node):
# disallow locally-cached paths, otherwise evaluating gives localised path
if node.knob('cacheLocal'):
orig = node['cacheLocal'].value()
node['cacheLocal'].setValue('never')
# Frame range to evaluate
fr = nuke.FrameRange(node['first'].value(), node['last'].value(), 1)
# Evaluation context thing, modified later
output_context = nuke.OutputContext()
files = []
for viewnumber in range(output_context.viewcount()):
# Loop over each view
# Skip "default" view
viewname = output_context.viewname(viewnumber)
if viewname not in nuke.views():
continue
# Set evaluation context view number
output_context.setView(viewnumber)
# Evaluate file for current view and frame
for framenum in fr:
# Loop over each frame
output_context.setFrame(framenum)
# ..and evaluate the file knob for this view/frame
evaluated_filepath = node['file'].getEvaluatedValue(output_context)
files.append(evaluated_filepath)
# Restore original cacheLocal setting
node['cacheLocal'].setValue(orig)
return files
print _collect_file_knob(nuke.selectedNode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment