set cut_paste_input [stack 0] version 13.1 v2 BackdropNode { inputs 0 name BackdropNode1 tile_color 0xc0c0c001 label "Switch Generator" note_font_size 100 selected true xpos -676 ypos 194 bdwidth 787 bdheight 228 } push $cut_paste_input NoOp { name MF_SwitchGenerator_v1_ 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 -332 ypos 348 addUserKnob {20 main} addUserKnob {4 type l Switch 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.\n\n-From-To:Switch to value 1 on a specified frame range." M {On "1-Frame only" From-To "" "" "" "" "" "" "" "" "" ""}} addUserKnob {3 inFrame l in} inFrame 1001 addUserKnob {22 setInFrame l "Set in" 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 out -STARTLINE +DISABLED} addUserKnob {22 setOutFrame l "Set out" 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 "" +STARTLINE T "
MF_SwitchGenerator v1.0 - manuelferia.com, April 2023
"} 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 specified frames.\n\n - 1-Frame only: Generates a switch node that switches on a specified frame only.\n\n - From-To: Generates a switch node that switches on a \"on\" specified frame and switches off on a\"off\" scecified frame.\n\n2.- Use buttons to set on and off frames. If desired, you can write the frames number instead.\n\n3.- Press the \"Generate Pulse\" button."} }