Thanks Ivan for your helpful answer. Very handy.

I've try to launch your python script from the script editor and it does 
exactly what I'm aiming for. My question now is how can I add those lines to my 
existing group/gizmo? Here you are the code of my Group, as you can see I've 
attached the code at the end but obviously it doesn't work.


#############################################

Group {
 inputs 0
 name V_Multilabeler1
 help "V!ctor 1.5v1\nV_Multilabeler\n©2011 Victor Perez. All rights 
reserved\nwww.victorperez.co.uk"
 xpos -2237
 ypos 52
 addUserKnob {20 V_Multilabeler}
 addUserKnob {18 target_tile_color l "tile color" t "Select a color for the 
tile"}
 target_tile_color {0.8 0.8 0.8}
 addUserKnob {41 target_label l label T LabelProperties.label}
 addUserKnob {41 note_font_1 l font T LabelProperties.note_font}
 addUserKnob {41 note_font_size_1 l "" -STARTLINE T 
LabelProperties.note_font_size}
 addUserKnob {41 note_font_color_1 l color -STARTLINE T 
LabelProperties.note_font_color}
 addUserKnob {26 space_01 l " " T " "}
 addUserKnob {6 box_tile_color l "change tile color" t "Change the tile color" 
+STARTLINE}
 box_tile_color true
 addUserKnob {6 box_label l "change label" t "Change the label" -STARTLINE}
 box_label true
 addUserKnob {22 execute_apply l Apply t "Apply changes to selected nodes" T 
"import colorsys\n\n# knobs to variables\ntarget_tile_color = 
nuke.thisNode().knob('target_tile_color').getValue()\ntarget_label = 
nuke.toNode('LabelProperties').knob('label').value()\nbox_tile_color = 
nuke.thisNode().knob('box_tile_color').value()\nbox_label = 
nuke.thisNode().knob('box_label').value()\n\n# RGB to HEX 
translator\ntarget_tile_color_r = target_tile_color\[0]\ntarget_tile_color_g = 
target_tile_color\[1]\ntarget_tile_color_b = target_tile_color\[2]\nhexColour = 
int('%02x%02x%02x%02x' % 
(target_tile_color_r*255,target_tile_color_g*255,target_tile_color_b*255,1), 
16)\n\n# tile color action\nif box_tile_color:\n    nuke.root().begin()\n    
for i in nuke.selectedNodes():\n        
i.knob('tile_color').setValue(hexColour)\nelse:\n    pass\n\n# label action\nif 
box_label:\n    nuke.root().begin()\n    for i in nuke.selectedNodes():\n       
 i.knob('label').setValue(target_label)\nelse:\n    pass" +STARTLINE}
 addUserKnob {22 execute_default l "Revert to Default" t "Revert to default 
color tile and/or label to selected nodes" -STARTLINE T "import colorsys\n\n# 
knobs to variables\ntarget_tile_color = 
nuke.thisNode().knob('target_tile_color').getValue()\ntarget_label = 
nuke.thisNode().knob('target_label').value()\nbox_tile_color = 
nuke.thisNode().knob('box_tile_color').value()\nbox_label = 
nuke.thisNode().knob('box_label').value()\n\n# tile color action\nif 
box_tile_color:\n    nuke.root().begin()\n    for i in nuke.selectedNodes():\n  
      i.knob('tile_color').setValue(0)\nelse:\n    pass\n\n# label action\nif 
box_label:\n    nuke.root().begin()\n    for i in nuke.selectedNodes():\n       
 i.knob('label').setValue(None)\nelse:\n    pass"}
 addUserKnob {26 space_02 l " " T " "}
 addUserKnob {26 automated_tasks l "Automated Tasks"}
 addUserKnob {22 execute_spectrum_tile_color l "Color Spectrum Tiles" t "Change 
the tile color of selected nodes with different steps of the color spectrum" T 
"import colorsys\n\nnuke.root().begin()\nvariations = 
len(nuke.selectedNodes())\nfor num,i in enumerate(nuke.selectedNodes()):\n    
newcolor = float(num)/float(variations)\n    setRGB = 
colorsys.hsv_to_rgb(newcolor, 1, 1)\n    # Float R, G, and B values for the 
color you're after\n    r = setRGB\[0]\n    g = setRGB\[1]\n    b = 
setRGB\[2]\n    hexColour = int('%02x%02x%02x%02x' % (r*255,g*255,b*255,1), 
16)\n    i\['tile_color'].setValue(hexColour)" +STARTLINE}
 addUserKnob {22 execute_class_in_label l "Node Class as Label" t "Change the 
label to selected nodes with its node class" -STARTLINE T 
"nuke.root().begin()\nfor i in nuke.selectedNodes():\n        
i.knob('label').setValue(nuke.selectedNode().Class())"}
 addUserKnob {26 attach_an_image l "Attach an Image"}
 addUserKnob {2 image_file l "image file" t "Browse for an image to be 
attached"}
 addUserKnob {22 execute_attach_image_to_nodes l "Attach Image" t "Attache the 
image selected in the previous knob to the selected nodes in the node graph" T 
"image_file = nuke.thisNode().knob('image_file').value()\nprint image_file" 
+STARTLINE}
 addUserKnob {22 execute_remove_image l "Remove Image" t "Remove any attached 
image in the selected nodes in the node graph" -STARTLINE}
}
 NoOp {
  inputs 0
  name LabelProperties
  selected false
  xpos 4
  ypos 261
 }
stringKnob = nuke.EvalString_Knob('image_file')
buttonKnob = nuke.PyScript_Knob('fileOpen', '<img 
src=":qrc/images/File_Knob.png">')
buttonKnob.setValue("""file = nuke.getClipname('Choose sequence...', pattern = 
'*.png', default ='/default/path')
if file:
   nuke.thisNode()['image_file'].setValue(file)
""")
nuke.thisNode().addKnob(stringKnob)
nuke.thisNode().addKnob(buttonKnob)
end_group


#############################################


By the way, the 'File_Knob.png' is the same as the default file icon but 
bigger, if it exists, do you know the name of the png image for the smaller 
version (same as Nuke default)?

Thanks a lot!


Victor

_______________________________________________
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