way for a function to understand whether it's being run through a OnCreate callback or not

Martin Vilcans martin at librador.com
Fri Jul 10 09:30:48 CEST 2009


On Fri, Jul 10, 2009 at 8:18 AM, slamdunk<s.deshe at gmail.com> wrote:
> is there a way for a function to understand whether it's being run
> through a OnCreate callback or not?
> I have working functions that I want to recycle through the OnCreate
> but need to catch the "nuke.thisNode()" bit inside them so they can
> still function when called manually through other scripts functions.

I suppose you're programming for The Foundry's Nuke. Python is used in
lots of different contexts, and most people on this list use Python
for something totally unrelated to video.

As an attempt at answering your question, you can add a parameter to
your function that tells from where it's called. I.e. you put True in
the parameter when it is called from OnCreate, False when it is not.
But that isn't a very good design. A function should not need to care
from where it is called. You probably want to have the node as a
parameter to the function instead of calling nuke.thisNode inside of
it.

I can't find documentation for the OnCreate function online. Do you
mean that you can only call nuke.thisNode() from inside OnCreate?

Here's my guess of what I think you want to do:

def OnCreate():
    # call your function with the current node as argument
    your_function(nuke.thisNode())

def your_function(node):
    # The function takes a node as an argument.
    # Do whatever you want here

For more Nuke-specific questions, you'd probably get better results by
asking on the Nuke-python mailing list:

http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python


-- 
martin at librador.com
http://www.librador.com



More information about the Python-list mailing list