set cut_paste_input [stack 0] version 14.0 v5 BackdropNode { inputs 0 name BackdropNode58 tile_color 0xc0c0c001 label "Switch Generator" note_font_size 100 selected true xpos 15 ypos -13202 bdwidth 808 bdheight 228 } push $cut_paste_input NoOp { name MF_SwitchGenerator knobChanged "n = nuke.thisNode()\nk = nuke.thisKnob()\n \nif k.name() == \"type\":\n # Disable out when no needed.\n if n\[\"type\"].getValue() in range(0,2):\n n\[\"outFrame\"].setEnabled(False)\n n\[\"setOutFrame\"].setEnabled(False)\n n\[\"outFrame\"].setValue(0) \n else:\n n\[\"outFrame\"].setEnabled(True)\n n\[\"setOutFrame\"].setEnabled(True)" selected true xpos 359 ypos -13024 addUserKnob {20 main} addUserKnob {4 type t "Type of switch generated:\n\n- On: Switch from 0 to 1 on a specified frame\n\n- 1-Frame only: Swith from 0 to 1 on a 1-frame only. Like a trigger\n\n-From-To:Switch to value 1 on a specified frame range." M {On "1-Frame only(Trigger)" From-To "" "" "" "" "" "" "" "" "" "" "" ""}} addUserKnob {3 inFrame l frame} inFrame 1001 addUserKnob {22 setInFrame l Set t "Press to set the in frame to the current frame." -STARTLINE T "a = nuke.thisNode()\nb = nuke.frame()\n\na\['inFrame'].setValue(b)"} addUserKnob {3 outFrame l to -STARTLINE +DISABLED} addUserKnob {22 setOutFrame l Set t "Press to set the out frame to the current frame." -STARTLINE +DISABLED T "a = nuke.thisNode()\nb = nuke.frame()\n\na\['outFrame'].setValue(b)"} addUserKnob {22 generateSwitch l "Generate Switch" T "#Set a default one shot trigger.\ndef generateSwitch(inFrame, outFrame, type):\n if t==2:\n if outFrame < inFrame:\n nuke.message(\"Please, check that \\\"off\\\" frame is higher than the \\\"on\\\" frame.\")\n return None\n \n #Create and set Trigger\n nSwitch = nuke.nodes.Switch()\n nSwitch.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n w = nSwitch\['which']\n w.setAnimated()\n w.setValueAt(0, inFrame - 1)\n w.setValueAt(1, inFrame)\n \n if t == 0:\n if (thisN\['labelOn'].getValue() == 1):\n nSwitch\['label'].setValue(\"
after Frame \" + str(inFrame) + \"\" + \"\\n Input: \" + \"\[if \{\[value this.which]==1\} \{return \\\"1\\\"\} \{return \\\"0\\\"\}]\" + \"
\")\n elif t == 1:\n w.setValueAt(0, inFrame + 1)\n if (thisN\['labelOn'].getValue() == 1):\n nSwitch\['label'].setValue(\"
only on Frame \" + str(inFrame) + \"\" + \"\\n Input: \" + \"\[if \{\[value this.which]==1\} \{return \\\"1\\\"\} \{return \\\"0\\\"\}]\" + \"
\")\n elif t == 2:\n w.setValueAt(1, outFrame)\n w.setValueAt(0, outFrame + 1)\n if (thisN\['labelOn'].getValue() == 1):\n nSwitch\['label'].setValue(\"
from Frame \" + str(inFrame) + \"\\n to Frame \" + str(outFrame) + \"\\n Input: \" + \"\[if \{\[value this.which]==1\} \{return \\\"1\\\"\} \{return \\\"0\\\"\}]\" + \"
\")\n \n#Get project and nuke variables\nthisN = nuke.thisNode()\nn = nuke.Root()\nfr = nuke.frame()\n\n#Get Trigger information\ninfr = int(thisN\['inFrame'].getValue())\noutfr = int(thisN\['outFrame'].getValue())\nt = thisN\['type'].getValue()\ngenerateSwitch(infr, outfr, t)" +STARTLINE} addUserKnob {6 labelOn l "Display info" t "Displays information on the node's label" -STARTLINE} labelOn true addUserKnob {26 _1 l "" +STARTLINE} addUserKnob {26 version_author l "" t "v1.1 update:\nChange layout a bit for more intuitive display." +STARTLINE T "
MF_SwitchGenerator v1.1 - manuelferia.com, Mar 2024
"} addUserKnob {20 help_1 l help} addUserKnob {26 howto l "How to use"} addUserKnob {26 explanation l "" +STARTLINE T "1.- Select the type of switch:\n\n - On: Generates a switch node that switches on a specificied frame.\n\n - 1-Frame only: Generates a switch node that switches on a specified frame only. Like a trigger.\n\n - From-To: Generates a switch node that switches on a specified frame range.\n\n2.- Use buttons to set on and off frames. If desired, you can write the frames number instead.\n\n3.- Press the \"Generate Switch\" button."} }