In python you call (i.e. execute) a function by calling it's name
followed by arguments in brackets:
e.g.:
myFunction()
"myFunction" without the brackets is the actual function object. You can
reference it by using it's name without brackets, e.g.:
refToFunction = myFunction
Then later, actually run that function like so (even via the newly
created reference:
refToFunction()
which is the same as calling myFunction() at this point
In the menu command you don't actually want to execute the function at
the stage where the menu.py is interpreted (ie. Nuke startup), you just
want to provide Nuke with the function object that is meant to be
executed when the user calls the respective menu entry, hence the lack
of brackets.
If you need to pass arguments as well you can either use a string like
this (not very pythonic):
nuke.menu("Nodes").addCommand("User/FiletypeConverter",
*"dh_pycode.fileconverter(arg1, ag2)"*)
Or a so called anonymous function via "lambda" :
nuke.menu("Nodes").addCommand("User/FiletypeConverter", *lambda:
dh_pycode.fileconverter(arg1, ag2)*)
"lambda" wraps up the function call in an nameless object (function) and
passes that on to Nuke to be executed later.
Does that make sense?
Cheers,
frank
On 23/10/16 2:48 AM, Daniel Hartlehnert wrote:
I already tried to start Nuke from the terminal mode but didn’t know
how to make it work. Thanks for the link!
Seeing the detailed error message now, it turns out it was some
indentation error in dh_pycode.py
There is one follow-up thing i am wondering about though:
When calling the function inside the .py file, there are no empty
brackets behind it.
nuke.menu("Nodes").addCommand("User/FiletypeConverter",
dh_pycode.fileconverter, ‚‘)
i would have expected dh_pycode.fileconverter() instead.
What i if i want to pass arguments to the function?
Am 22.10.2016 um 14:36 schrieb Justin GD <j.grosde...@gmail.com
<mailto:j.grosde...@gmail.com>>:
You need to launch Nuke in terminal mode so we can see exactly the
error.
You can follow the doc for that :
http://help.thefoundry.co.uk/nuke/content/getting_started/installation/launching_nuke_mac.html
Alternatively, you might be able to see it when you click "show
more", in the pop up error window.
Also, make sure your dh_pycode.py is added to the nuke path, in your
init.py if it's in a sub folder.
Cheers,
J
2016-10-22 13:12 GMT+01:00 Daniel Hartlehnert <dah...@gmx.de
<mailto:dah...@gmx.de>>:
Hi Justin,
i am on OS X, i don’t see any terminal when starting Nuke.
I commented out every line in dh_pycode.py, but still i get the
same error.
Am 22.10.2016 um 13:28 schrieb Justin GD <j.grosde...@gmail.com
<mailto:j.grosde...@gmail.com>>:
Hi Daniel,
Can you send the full error message ? In your terminal, you
should have the error line / file indicated.
This is most likely an error in your dh_pycode file.
Cheers,
Justin
2016-10-22 12:08 GMT+01:00 Daniel Hartlehnert <dah...@gmx.de
<mailto:dah...@gmx.de>>:
Hi,
in my .nuke folder i have a text file called dh_pycode.py
It contains several functions i want to call in my menu.py
like this:
import sys
import nuke
import dh_pycode
nuke.menu("Nodes").addCommand("User/FiletypeConverter",
dh_pycode.fileconverter, '‘)
i always get the message „error interpreting this plug-in“
when starting nuke.
There are other menu entries added in the menu.py which are
not calling functions from the dh_pycode.py. When i comment
out „import dh_pycode“ and its corresponding menu entry,
everything works.
How do you call external python code in menu.py?
Daniel
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
<http://forums.thefoundry.co.uk/>
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
<http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users>
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/ <http://forums.thefoundry.co.uk/>
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
<http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users>
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/ <http://forums.thefoundry.co.uk/>
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
<http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users>
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk
<mailto:Nuke-users@support.thefoundry.co.uk>,
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users