The bug seems to be that the expression editor window doesn’t properly parse 
the curly braces out of python expression strings. I’ve filed a ticket for this.

-Nathan



From: andi 
Sent: Friday, May 18, 2012 9:40 PM
To: [email protected] 
Subject: [Nuke-python] Re: activate python mode when using expression

This is excellent solution, i've been dealing with this 'calling python twice' 
for long time, i didn't know the -execlocal solve that issue. Thanx. Btw there 
some weird problem with nuke behaviour when using the code we're talking about.

here code #1

      Code:  
      nuke.selectedNode().knob('translate').setExpression('''[python -execlocal 
{x = 2 
      for i in range(100): 
          x += i 
      ret = x}]''', 0)  


when i use that code, the knob is executing the expression correctly, i can see 
the value is changed to the correct value, but when i open the knob (edit 
expression) , i see error msg : invalid syntax. That error came from the '{' 
and '}' . So i remove the curly brackets, and error msg are gone. So i modified 
the script to remove the curly brackets :

      Code:  
      nuke.selectedNode().knob('translate').setExpression('''[python -execlocal 
x = 2 
      for i in range(100): 
          x += i 
      ret = x]''', 0)  


check the knob, it has zero value. Look like the expression error. But when 
open the expression (edit) , the code is perfect and now i just hit 'OK' 
without editing anything. Now knob got correct value.

Seems to be a bug. Don't you think ? has it been logged as bug?

Cheers


      NathanR wrote:  
      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


     



--------------------------------------------------------------------------------
_______________________________________________
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

Reply via email to