Yes, those will all do the same thing.

-Nathan



From: Matthew Doll 
Sent: Monday, November 17, 2014 2:26 PM
To: Nuke Python discussion 
Subject: Re: [Nuke-python] "lambda" or \"xyz\"

OK cool I think I understand... to confirm then, these three examples are all 
equivalent:

m.addCommand("Add My Slate", "nuke.createNode('mySlate')")
m.addCommand("Add My Slate", "nuke.createNode(\"mySlate\")")
m.addCommand("Add My Slate", lambda: nuke.createNode("mySlate"))

Where 'mySlate' is a gizmo sourced in the plugin_path. 


Is that right? I have been using the first syntax for years, the others seem 
more complicated than necessary if indeed they're equivalent.

Thanks for the tips!
-Matt







On Mon, Nov 17, 2014 at 1:51 PM, Nathan Rusch <nathan_ru...@hotmail.com> wrote:

  The first form uses a string argument, and the backslashes are there to 
escape the double quotes inside other double quotes. You could replace either 
the inner or outer quote pairs with single quotes in that example and get rid 
of the backslashes.

  The second example (using "lambda: ") creates an anonymous function that 
takes no arguments and which just calls `nuke.createNode("Blur")` when called, 
and then binds the resulting function to the menu command.

  If you use the string form, the string will be exec'ed when the menu command 
is invoked. If you use a callable, it will be called (with no arguments).

  You can't use `m.addCommand("Filters/Blur", nuke.createNode("Blur"))`, 
because `nuke.createNode("Blur")` will be called when the addCommand method is 
called (while the menus are being built). In other words, you will be trying to 
pass a created node to `m.addCommand()`.

  -Nathan



  From: Matthew Doll 
  Sent: Monday, November 17, 2014 1:15 PM
  To: Nuke Python discussion 
  Subject: [Nuke-python] "lambda" or \"xyz\"

  In the docs about adding menu items it mentions both: 

  m.addCommand("Filters/Blur", "nuke.createNode(\"Blur\")" )
  or its alternative:
  m.addCommand("Filters/Blur", lambda: nuke.createNode("Blur") )


  I'm not clear what is the functionality here, why not:
  m.addCommand("Filters/Blur", nuke.createNode("Blur"))

  I can't find any references on this list or in the docs to what exactly those 
backslashes or "lambda:" actually do.

  Thanks,
  Matt

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





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