you are right Frank, thanks it's better to add condition test to the nodeChanged of the node with a pulldown knod added. In this sample :red, green, blue, yellow
code='''
k=nuke.thisKnob()
if k.name() == 'color':
tc=n['tile_color']
c=k.getValue()
enumColor = [ [1, 0, 0] ,[0, 1, 0] ,[0, 0, 1] ,[1, 1, 0] ]
r = enumColor[int(c)][0]
g = enumColor[int(c)][1]
b = enumColor[int(c)][2]
hexColour = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1),16)
tc.setValue(hexColour)
'''
nuke.selectedNode()['knobChanged'].setValue(code)
2014-03-15 18:40 GMT-04:00 Frank Rueter|OHUfx <[email protected]>:
> indeed. that is the difference between Oliver's and my replies.
>
>
> >>This code is executed constantly, so be very careful to put most of your
> code in conditionals with the relevant knob name, and keep it simple.
> >>Otherwise your scripts can really grind to a halt!
>
> Yup, which is why I always try to do the conditional statements at the
> very top and try to bail out at the first possible moment.
> You definitely want to be extra diligent with your code's efficiency if
> used as a global callback.
>
>
>
>
> On 3/16/14, 10:52 AM, Jed Smith wrote:
>
> It is also worth mentioning that knobChanged callback code can be
> specified in the menu.py file, applying to an entire node class, or
> knobChanged code can be stored and run in specific nodes only.
>
> To store knobChanged code in a specific node, you can store the code to
> a special hidden knob called "knobChanged". This code will the be executed
> anytime you change anything on the node.
>
> For example, if you have a noOp node with a dropdown menu specifying
> colors, like this:
> NoOp {
> name NodeColor
> addUserKnob {20 NodeColor}
> addUserKnob {4 node_color t "Set Node Color" M {red green blue yellow}}
> }
>
> And you write some code to change the color of the node depending on the
> dropdown value, you can set the value of the knobChanged knob on that node
> if you select the node and execute this code:
> http://pastebin.com/mCPm5HkZ
>
> Be careful with knobChanged knobs in nodes though. This code is executed
> constantly, so be very careful to put most of your code in conditionals
> with the relevant knob name, and keep it simple. Otherwise your scripts can
> really grind to a halt!
>
> Hope that helps!
>
> On Saturday, 2014-03-15 at 2:12p, Bruno-Pierre Jobin wrote:
>
> Awesome! Thanks guys I'll have a look at this!
>
>
> On Sat, Mar 15, 2014 at 5:03 PM, Frank Rueter|OHUfx <[email protected]>wrote:
>
> Here is something to get you started:
>
> http://pastebin.com/2SbLf5PH
>
> This adds a callback for nodes of class "NoOp", which you will have to
> change to react to your gizmo class or whatever other node you want this to
> work with.
>
>
> Have a look and see if it makes sense.
>
> Cheers,
> frank
>
>
>
> On 3/16/14, 8:37 AM, Bruno-Pierre Jobin wrote:
>
> Hello Nukers,
>
> I'm trying to find a way to change the color of a node (title_color)
> which would be driven by cascading pulldown choice menu. For example, if
> the first item is chosen, the node would be yellow and if the second one is
> chosen, it would turn blue.
>
> I found this thread in the mailing list archive but I can't figure out
> where to paste that code...
>
>
> https://www.mail-archive.com/[email protected]/msg03405.html
>
> I'm very new to python so please give a lot of details.
>
> Thanks!
> --
> Bruno-Pierre Jobin
>
>
>
> _______________________________________________
> Nuke-users mailing [email protected],
> http://forums.thefoundry.co.uk/http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
>
> --
> [image: ohufxLogo 50x50] <http://www.ohufx.com> *vfx compositing
> <http://ohufx.com/index.php/vfx-compositing> | workflow customisation and
> consulting <http://ohufx.com/index.php/vfx-customising> *
>
> _______________________________________________
> Nuke-users mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
>
>
>
> --
> Bruno-Pierre Jobin
> www.bpjobin.com
> _______________________________________________
> Nuke-users mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
>
>
>
> _______________________________________________
> Nuke-users mailing [email protected],
> http://forums.thefoundry.co.uk/http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
>
> --
> [image: ohufxLogo 50x50] <http://www.ohufx.com> *vfx compositing
> <http://ohufx.com/index.php/vfx-compositing> | workflow customisation and
> consulting <http://ohufx.com/index.php/vfx-customising> *
>
> _______________________________________________
> Nuke-users mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
>
<<inline: image/png>>
<<inline: ohufxLogo_50x50.png>>
_______________________________________________ Nuke-users mailing list [email protected], http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
