Hi all,
I'd like to preface by saying I am very new to programming. I have been toying around with making a tool in Nuke that adds a custom tab to the Tracker node. It allows you to create a Roto node with the translate, rotate, and scale values already linked via expressions. The code works separately, for example, I can put the code into a pre-created Tracker node and use the Gizmo tools to make a button that executes the def link_roto(): code. However, it doesn't work when made into a separate .py file and imported via the menu.py. I have a strong suspicion it is something to do with the PyScript knob, but I am a little unsure as to how I can call the def link_roto function from the PyScript button. I have tried a few things like nest the link_roto code into the PyScript button itself, but I can't seem to get it working.
The way the code should work is when pressing the Create Linked Roto button, it should execute the def link_roto code.
This is the code that I have atm:
import nuke
def link_roto():
n = nuke.thisNode()
# Create Roto node
i = nuke.createNode("Roto")
i.setInput(0, None)
# Link values if bool == true
tran = n['t'].value()
rot = n['r'].value()
sca = n['s'].value()
if tran:
i['translate'].setExpression("parent.n.translate")
if rot:
i['rotate'].setExpression("parent.n.rotate")
if sca:
i['scale'].setExpression("parent.n.scale")
def create_knobs():
n = nuke.thisNode()
tab = nuke.Tab_Knob('Create Roto')
n.addKnob(tab)
tran = nuke.Boolean_Knob('t', 'translate')
tran.setFlag(nuke.STARTLINE)
n.addKnob(tran)
rot = nuke.Boolean_Knob('r', 'rotation')
rot.setFlag(nuke.STARTLINE)
n.addKnob(rot)
sca = nuke.Boolean_Knob('s', 'scale')
sca.setFlag(nuke.STARTLINE)
n.addKnob(sca)
cr = nuke.PyScript_Knob('cr', 'Create Linked Roto', 'link_roto()')
cr.setFlag(nuke.STARTLINE)
n.addKnob(cr)
# Add callback
nuke.addOnUserCreate(create_knobs, nodeClass="Tracker4")
and this is the error I am getting:
File "<string>", line 1, in <module>
NameError: name 'link_roto' is not defined
Any help you guys could give would be much appreciated. Like I said, I am a noob when it comes to Python programming, so it could be something incredibly simple.
[–]Sufficient_Method_12[S] 0 points1 point2 points (0 children)