knob auto updating

I’m trying to create a script for rendering stereoscopic views. The script detects a bunch of stuff in the node tree and creates separate write nodes for the left and right eye views.

The trouble I’m having is my testing artists have requested that I make the views auto-update if the filename is changed. I originally thought I could do this with a tcl expression but the problem is, in the required naming convention, the left eye view needs a "-L" at the end of the filename and the right eye view needs a "-R". So I somehow need to copy all of the information from leftWrite.knob(‘file’) excepth the last 11 characters. That isn’t so difficult but I’m having trouble getting it to update automatically. Is there any way to make the file knob in the right eye view write node update itself (minus 11 characters) whenever the file knob in the left eye view write node is changed?

PS Forgive my script if it seems daft, I’ve only been using python for a week. :confused:

Code:

def typeFinder(current, target):
    dependent = nuke.dependencies(current)
    if (len(dependent) > 0):
        for n in dependent:
            if (n.Class() == 'Read') and (len(nuke.channels(n)) > 1):
                path = n.knob('file').value()
                Ftype = path[-3:]
                target.knob('file_type').setValue(Ftype[:3])
            else:
                typeFinder(n, target)
               
def colorspaceFinder(current, target):
    dependent = nuke.dependencies(current)
    if (len(dependent) > 0):
        for n in dependent:
            if (n.Class() == 'Read') and (len(nuke.channels(n)) > 1):
                readColor = n.knob('colorspace').value()
                target.knob('colorspace').setValue(readColor)
            else:
                colorspaceFinder(n, target)

def stereoWrite():
    current = nuke.selectedNode()
    folderName = ''
    nameInput = ''
    panel = nuke.Panel("Render Path")
    panel.addFilenameSearch("Please choose a folder to render to:", folderName)
    panel.addSingleLineInput("Please input a name for the rendered files:", nameInput)
    panel.show()
    folder = panel.value("Please choose a folder to render to:")
    name = panel.value("Please input a name for the rendered files:")
    if (folder == ""):
        nuke.message("Please specify a render folder.")
    if (name == ""):
        nuke.message("Please specify a file name.")

    leftWrite = nuke.nodes.Write(name = 'Left Eye View')
    leftWrite.knob('channels').setValue('all')
    colorspaceFinder(current, leftWrite)
    typeFinder(current, leftWrite)
    extensionL = leftWrite.knob('file_type').value()
    leftWrite.knob('tile_color').setValue(4278190335L)
    leftWrite.setInput(0, current)
    leftWrite.knob('views').setValue('left')
    leftWrite.knob('file').setValue(folder + name + ".%04d-L." + extensionL)
    dependentL = nuke.dependencies(leftWrite)
    for n in dependentL:
        x = n.xpos()
        leftWrite.setXpos(x - 100)
        y = n.ypos()
        leftWrite.setYpos(y + 75)
   
    rightWrite = nuke.nodes.Write(name = 'Right Eye View')
    rightWrite.knob('channels').setValue('all')
    colorspaceFinder(current, rightWrite)
    typeFinder(current, rightWrite)
    extensionR = rightWrite.knob('file_type').value()
    rightWrite.knob('tile_color').setValue(16711680L)
    rightWrite.setInput(0, current)
    rightWrite.knob('views').setValue('right')
    rightWrite.knob('file').setValue(folder + name + ".%04d-R." + extensionR)
    dependentR = nuke.dependencies(rightWrite)
    for n in dependentR:
        x = n.xpos()
        rightWrite.setXpos(x + 100)
        y = n.ypos()
        rightWrite.setYpos(y + 75)


Forgot to mention, the naming convention follows the following pattern:
"path" / "clip_name" ".%04d" "stereo extension" "file type extension"

No Responses to “knob auto updating”

Post a Comment