I have been trying to learn some Python to improve my workflow when I use The Foundry NUKE. I have been making various overrides that change the nodes upon creation. One of them being a StickyNote
I had this override before for it:
def setColor(R,G,B):
return int("%02x%02x%02x%02x" % (R,G,B,1),16)
def StickyNoteOverride():
nuke.thisNode()["tile_color"].setValue(setColor(R=(255*.298),G=(255*.298),B=(255*.298)))
nuke.thisNode()["note_font_size"].setValue(60)
nuke.thisNode()["note_font_color"].setValue(setColor(R=(255),G=(255*.624),B=(255*.0)))
nuke.thisNode()["note_font"].setValue("Deja Vu Sans Bold")
and it worked giving me expected results but then I tried to have it clear the label upon creation to be empty.
So I added this line to the bottom:
nuke.thisNode()["label"].setValue("")
and it did not set the value of the label to nothing.
So I changed it up a bit to:
def StickyNoteOverride():
noteNode = nuke.createNode("StickyNote")
noteNode["tile_color"].setValue(setColor(R=(255*.298),G=(255*.298),B=(255*.298)))
noteNode["note_font_size"].setValue(60)
noteNode["note_font_color"].setValue(setColor(R=(255),G=(255*.624),B=(255*.0)))
noteNode["note_font"].setValue("Deja Vu Sans Bold")
noteNode["label"].setValue("")
Now this script creates the node with values set as expected but for me it's creating like 200 of the nodes till it errors out. All of this is being addressed/called at bottom of my menu.py
file with:
nuke.addOnUserCreate(StickyNoteOverride, nodeClass = "StickyNote")
I am looking for some help to figure a way out to add the label to be empty upon creation.
Thanks, hopefully this is understandable.
Try this (it definitely works in Script Editor
):
import nuke
import nukescripts
m = toolbar.addMenu("Other", "ToolbarOther.png")
m.addCommand("StickyNote", "nukescripts.toolbar_sticky_note()", "#n", icon="StickyNote.png")
def toolbar_sticky_note():
sticky = nuke.createNode("StickyNote")
sticky.knob("label").setValue("")
sticky.knob("selected").setValue(False)
toolbar_sticky_note()
And try this (it works in menu.py
):
m = toolbar.addMenu("Other", "ToolbarOther.png")
m.addCommand("StickyNote", "nuke.createNode('StickyNote')", "#n", icon="StickyNote.png")
or this syntax:
m = toolbar.addMenu("Other", "ToolbarOther.png")
m.addCommand("StickyNote", "nuke.createNode('StickyNote', 'label <H6>test</H6> note_font Phosphate')", "#n", icon="StickyNote.png")