Nuke script: Read node from Write node

Originally posted in 2011; A Python script for Nuke which takes any selected Write (or Read) node and creates a Read node from it. Now updated to fix some bugs and support for a wider range of scenarios.

The script will actually not look for Write nodes in the selection. Instead, it’ll look for a specific knob in each of the selected nodes. If the knob is found in the node, the script will attempt to detect an image sequence or movie file based on the knob value (expressions are supported) and then create a Read node with the detected imagery. By default, the script will look for the file knob, which makes it compatible with Write, Read and possibly other nodes too. You can make the script look for other knobs by adding their names to the FILEPATH_KNOBS list, which is particularly useful if you’re into customization.

See more about these settings a bit further down.

Download

Installation instructions

Place the Python script in the /scripts dir inside your NUKE_PATH (see my previous post on setting this up). Add the following to your menu.py:

import readFromWrite
nuke.menu( 'Nuke' ).addCommand( 'My file menu/Read from Write', 'readFromWrite.ReadFromWrite()', 'shift+r' )

You should now be able to select any Write node(s) and hit shift+r to generate corresponding Read node(s)!

Release notes / changelog

Changelog:
- v2.3:
    - Bug fix: crash when knob "use_limit" isn't available on node
    - Accidentally left ReadFromWrite() at bottom of script in v2.2
- v2.2:
    - Support for nodes with filepath which does not exist on disk
      (will read Write node settings or incoming framerange)
    - Support for additional Read/Write node option "raw"
v2.1:
  - Fixed bug where Read node always got premultiplied
  - Support for ../ in filepath/expression
  - Dialog on "filepath not found" error
  - Set origfirst, origlast framerange
  - Additional movie file format support (see SINGLE_FILE_FORMATS variable)
  - General cleanup of various methods for greater maintainability
v2.0:
  - Completely rewritten from scratch
  - Improved detection of frame range
  - Supports any padding format (not only %04d)
  - Applies colorspace to Read node
  - Supports not only Write nodes (see FILEPATH_KNOBS variable)
  - Supports definition of "single file image sequence" formats (see SINGLE_FILE_FORMATS variable)
  - PEP8 compliant!

Settings

Look in the top portion of the file for the settings definitions:

# Settings
#
# knob names to use (from any node) as a base for Read node creation.
FILEPATH_KNOBS = ['file']
#
# This scripts needs to know whether to apply padding to a filepath
# or keep it without padding. Movie files should not have padding,
# for example. Add such "single file formats" here.
SINGLE_FILE_FORMATS = ['avi', 'mp4', 'mxf', 'mov', 'mpg',
                       'mpeg', 'wmv', 'm4v', 'm2v']