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

Reply via email to