Q100343: How to automatically create OCIOCDLTransform soft effects and set .cc file paths for clips in Nuke Studio and Hiero

Follow

SUMMARY

This article explains how you can use Python to automatically create a OCIOCDLTransform soft effect for each clip in your Nuke Studio or Hiero timeline, and define the ASC CDL file path for each shot.

 

MORE INFORMATION

When you manually create OCIOCDLTransform soft effects for clips inside NukeStudio or Hiero, you can create one effect at a time for each clip, then manually have to set the .cc file path for each of the soft effects.

This can be rather time consuming, particularly if you have a lot of shots in your timeline and each one has it’s own .cc file to apply.

However, you can use Python to automate this setup and below is the example code that creates a OCIOCDLTransform soft effect for each clip and applies a different .cc file path to each soft effect:

for trackItem in [y for x in hiero.ui.activeSequence().videoTracks() for y in x.items()]:
trackItemEffect = trackItem.parentTrack().createEffect("OCIOCDLTransform",trackItem=trackItem )
trackItemEffect.node()["read_from_file"].setValue(1)
shotNumber = trackItem.name()[trackItem.name().rfind("_")+1:]
ocioPath = "/path/to/CDL/shot_" + shotNumber + ".cc"
trackItemEffect.node()["file"].setValue(ocioPath)

 

Breaking down the code line by line, here is an explanation of what each line does:

1. for trackItem in [y for x in hiero.ui.activeSequence().videoTracks() for y in x.items()]:

This first line creates a for loop and iterates through all the clips in the timeline. The rest of the code is then applied to each clip at a time within the list of timeline clips.

The hiero.ui.activeSequence().videoTracks() command queries the currently active sequence on the timeline, loops through all the clip items of each video track and adds them to a Python list. This creates the full list of clips to apply the commands from the next lines to. 

2. trackItemEffect = trackItem.parentTrack().createEffect("OCIOCDLTransform",trackItem=trackItem )

This second line creates the soft effect and adds it to the current clip we're on in the for loop. 


3. trackItemEffect.node()["read_from_file"].setValue(1)

This third line sets the 'read from file' knob value on the soft effect created for the current clip.


4. shotNumber = trackItem.name()[trackItem.name().rfind("_")+1:]

This fourth line generates the shot number of the clip. This works by querying the shot name, finding the last underscore and splitting the name of the shot to leave just the shot number.


5. ocioPath = "/path/to/CDL/shot_" + shotNumber + ".cc"

This fifth line generates the path to the .cc file by using the location path and file naming convention, and concatenating it to the shot number and the .cc file extension.


6. trackItemEffect.node()["file"].setValue(ocioPath) 

This last line sets the soft effects file path to the one generated in line 5.

 

NOTE: The code works based on an established naming convention for shots and for the .cc file paths. To adapt this to your workflow you will need to adjust lines 4 and 5 to match the naming convention used for your project.

 

Below is the result of the code being run within the Script Editor and the OCIOCDLTransform soft effects being created for all clips within the Nuke Studio timeline:

 

    We're sorry to hear that

    Please tell us why