Hey Jep!
I didn't realize that it was possible to call a more elaborate function
when registering the toolbar command, but have been sent a few examples
that do as you show. So, I've got something like:
def makeAConfiguredNode():
node = nuke.createNode( 'contrivedExample' )
# get relevant data to configure node with...
node.knob( 'relevantConfigData' ).setValue( dataIJustGot )
# And then in menu.py,
toolbar.addCommand( "Other/contrivedExample", "makeAConfiguredNode()",
icon="contrivedExample.png" )
So I've got this thing on the run.
Thanks everybody for your help!
Chris
On Thu, Jan 26, 2012 at 7:31 AM, Jep Hill <[email protected]> wrote:
> Hi Chris,
>
> Not a dumb question at all... I'm not sure this will be helpful, but if I
> understand your question, have you thought of using a callback? i.e. when
> the node is created, if input 1 is connected, do this -- if input 2 is also
> connected, do that... otherwise do something else. There are a wide range
> of callbacks you can choose from -- one will take action only when the node
> is created, another will take action when the user does "specified action",
> etc.
>
> You can add your callback to your menu.py file (since it's GUI related) --
> first you define the function your callback will execute, then you define
> the callback it... here's a pseudo example:
>
> def mySweetFunction():
> n=nuke.thisNode()
> if n.Class()=="Read":
> print "You have just created a new Read node named %s" %
> n.name()
>
> ### this function will print the Read nodes name every time a new read
> node is created -- but only if you put it into action by using it in a
> callback
>
> nuke.addOnCreate(mySweetFunction, nodeClass = "Read")
>
> ### Notice the lack of parentheses after my function "mySweetFunction"
> when I pass the function to call in the callback -- you are telling the
> callback which function to call, rather than calling it at that time...
> this something that can confuse people.
>
> With regard to your question about defining variables for a node upon
> creation -- you could set knobs upon creation by sniffing for things but a
> callback is easier...
>
> Is there a reason you prefer nuke.createNode("Node") as opposed to
> nuke.nodes.Node(name="hello",label="world")?
>
> The second is much easier to define values inline, however both can have
> knob values defined after the node creation quite easily, like so:
>
> myNode=nuke.createNode("NoOp")
> myNode['name'].setValue("Hello") # I find this shorthand method preferable
> to the longhand equivalent: myNode.knob('name').setValue('hello')
>
> Again, if I understand your question, I would use a callback and then
> tweak the knob values as I have described above...
>
> Hope this helps...
>
> Cheers,
> Jep_______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
--
I think this situation absolutely requires that a really futile and stupid
gesture be done on somebody's part. And we're just the guys to do it.
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python