I have noticed speed hits for complex Python expressions in some situations, so
I generally try to avoid them whenever possible.
As far as making the expressions more readable, you’re right that you can use
curly braces and triple-quoted strings to avoid escaping things. However,
there’s no reason to make 2 calls to the [python] command; it’s cleaner and
more efficient to just use –execlocal and assign to ret at the end.
nuke.selectedNode().knob('translate').setExpression('''[python –execlocal {x = 2
for i in range(100):
x += i}]
ret = x''', 0)
-Nathan
From: andi
Sent: Thursday, May 17, 2012 8:14 PM
To: [email protected]
Subject: [Nuke-python] Re: activate python mode when using expression
Hi Nathan, Thanx a lot for the code. I got a question, for complex calculation
u ever had, did it make a difference in speed when running python from tcl
[python .. ] compared to running python code by itself.
Another thing, reading your script, giving me another idea to solve ... which
not simpler but maybe more 'readable' ?
rather than doing execlocal and those bunch of '\\' , i use -exec, i add
header/footer to my code , so my code will be between the '[python -exec {' and
'}][python x]' where in this case, x is the output variable.
Code:
[python -exec {
x=2
for i in range(100):
x+=i
}][python x]
copy/paste that code directly into knob where i want to use the code. Or using
python to inject the code :
Code:
scr='''
[python -exec {
x=2
for i in range(100):
x+=i
}][python x]
'''
nuke.selectedNode().knob('translate').setExpression(scr,0)
Thanx
--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python