Anyone get a chance to look into this?

I know it takes a little bit to setup / test / and show the problem. But we are still at a loss to why nuke.metadata() is "writing" incorrect text to the frame its writing for.


On 02/14/2013 07:16 PM, Thomas Craigen wrote:

I have been spending a bit of time trying to get this to work. I have not been able to produce the correct results when setting the "message" knob on a text node.

Originally, I tried using an event hook to "process" the read nodes. You can see commented section in the example below.

*Problem: *It appears that if I use node.metadata() before the frame renders, then try to set the Text.message knob, the data for the first frame is written to both the "first" and "second" frame. All frames after that appear to be offset by -1. So it appears that its reading data from 0-2 instead of 1-3. However, printing the same exact data to stdout shows the data to be correct. Its only the composite image that is incorrect.

I have provided a sample script. At the bottom of the script is the "nuke" script I used to generate the test frames (frame1: red, frame2: green, frame3:blue)

I have put some comments inline, see ### PROBLEM AREA ### for the section that does not seem to be working.



*simple.py:*

def GetData(node):
    mdata = node.metadata()
    filename = mdata.get('input/filename')
    return filename

def AddMetadataToTextNodes(*args, **kwargs):
    """callback: This callback is designed to
    update the data on-the-fly within this script only
    """
    textnode = kwargs.get('textnode')
    readnode = kwargs.get('readnode')
    metadata = readnode.metadata() ### appears to get the correct data
    filename = metadata.get('input/filename')
    #textnode.evaluate()
    print "setting data:", filename
    ### PROBLEM AREA ###
    ### some reason filename prints just fine
### however, the output in the "composited" frame shows the "previous" frame ### tcl works as does calling the GetData() function... what am I doing wrong? textnode.knob('message').setValue('metadata:' + str(filename) + ' tcl: [metadata input/filename] py: [python GetData(nuke.thisNode())]')
    nuke.dependentNodes(textnode, evaluateAll=True)


def RunComp(path=None, outcomp=None):


    ### NOTE: I tried doing event hooks, however, this also did not work
    """
nuke.removeBeforeRender(AddMetadataToTextNodes,args=(asset_info, node_state_info),nodeClass='Write') nuke.addBeforeRender(AddMetadataToTextNodes,args=(asset_info, node_state_info),nodeClass='Write') nuke.removeAfterFrameRender(AddMetadataToTextNodes,args=(asset_info, node_state_info),nodeClass='Write') nuke.addAfterFrameRender(AddMetadataToTextNodes,args=(asset_info, node_state_info),nodeClass='Write')
    """
    if not outcomp:
        outcomp = os.environ.get('TEMP', None)
    if not outcomp:
        if sys.platform.startswith('win'):
            outcomp = 'C:/temp/'
        else:
            outcomp = '/tmp/'
    if path:
        readnode = nuke.nodes.Read(file="%s" % path)
        textnode = nuke.nodes.Text()
        final_write = nuke.nodes.Write()
        outimages = os.path.dirname(path) + '/outimages.####.exr'
        outimages = outimages.replace('\\', '/')
        final_write.knob("file").setValue(outimages)

        textnode.connectInput(0, readnode)
textnode.knob('font').setValue('[python BfdNuke.getFontDir()]Arial.ttf')
        #textnode
#textnode.setExpression('[python {nuke.thisNode().knob(\'msg\').getValue()} ]')
        final_write.connectInput(0, textnode)
        outcomp = os.path.join(outcomp, 'comp.nk')
        outcomp = outcomp.replace('\\','/')
        if outcomp.endswith('.nk'):
            nuke.scriptSave( outcomp )
            print "Wrote: %s" % outcomp
        else:
print "WARNING: Unable to write 'outcomp' since it does not end with '.nk': %s was specified."
        firstFrame = 1
        lastFrame = 4
        readnode.knob('first').setValue(firstFrame)
        readnode.knob('origfirst').setValue(firstFrame)
        readnode.knob('last').setValue(lastFrame)
        readnode.knob('origlast').setValue(lastFrame)
        for i in range(firstFrame, lastFrame):
            AddMetadataToTextNodes(readnode=readnode, textnode=textnode)

### PROBLEM AREA ###
### appears to write the incorrect data when using node.metadata()
            nuke.execute(final_write, i, i, 1)
    else:
raise ValueError("Must provide a path in nuke style string: /path/to/dir/files.####.exr")

if __name__ == '__main__':
### does not check if frames exist. generate test frames before running
    RunComp('/tmp/test.####.exr')

    ### use the script by calling nuke -t 'path_to_script/simple.py'
#### NUKE SCRIPT USED TO GENERATE TEST FILES ####
"""

set cut_paste_input [stack 0]
version 7.0 v1
Constant {
 inputs 0
 channels rgb
 color {0 0 1 0}
 name Constant3
 selected true
 xpos 71
 ypos -148
}
Write {
 file /tmp/test.0003.exr
 file_type exr
 name Write3
 selected true
 xpos 71
 ypos -76
}
Constant {
 inputs 0
 channels rgb
 color {1 0 0 0}
 name Constant1
 selected true
 xpos -123
 ypos -155
}
Write {
 file /tmp/test.0001.exr
 file_type exr
 name Write1
 selected true
 xpos -123
 ypos -68
}
Constant {
 inputs 0
 channels rgb
 color {0 1 0 0}
 name Constant2
 selected true
 xpos -27
 ypos -151
}
Write {
 file /tmp/test.0002.exr
 file_type exr
 name Write2
 selected true
 xpos -27
 ypos -69
}

"""



_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to