set cut_paste_input [stack 0]
version 13.2 v8
BackdropNode {
inputs 0
name BackdropNode35
tile_color 0xc0c0c001
label "Pulse Generator"
note_font_size 100
selected true
xpos 43593
ypos 296028
bdwidth 761
bdheight 259
}
push $cut_paste_input
NoOp {
name MF_PulseGenerator
knobChanged "n = nuke.thisNode()\nk = nuke.thisKnob()\nif k.name() == \"apply\":\n n\[\"pValue\"].setEnabled(n\[\"apply\"].getValue()!=0)\n \nif k.name() == \"type\":\n # Disable length when no need it\n if n\[\"type\"].getValue() in range(1,4):\n n\[\"length\"].setEnabled(False)\n n\[\"length\"].setValue(1)\n else:\n n\[\"length\"].setEnabled(True)\n # Disable expression when no need it\n if n\[\"type\"].getValue() in range(0,3):\n n\[\"expression\"].setValue(\"\")\n n\[\"expression\"].setEnabled(False)\n n\[\"expression\"].setVisible(False)\n else:\n n\[\"expression\"].setEnabled(True)\n n\[\"expression\"].setVisible(True)\n # Disable expression when no need it\n if n\[\"type\"].getValue() in range(1,3):\n n\[\"hlSpacing\"].setValue(1)\n n\[\"hlSpacing\"].setEnabled(False)\n else:\n n\[\"hlSpacing\"].setEnabled(True)\n \n if n\[\"type\"].getValue() == 5:\n n\[\"addFrame\"].setVisible(True)\n else:\n n\[\"addFrame\"].setVisible(False)\nif k.name() == \"frameRng\":\n n\[\"startFrame\"].setEnabled(n\[\"frameRng\"].getValue()!=0)\n n\[\"endFrame\"].setEnabled(n\[\"frameRng\"].getValue()!=0)\n \n#if k.name() in (\"aValue\", \"length\", \"lvalue\", \"apply\",\"type\", \"interpolation\", \"expression\",\"frameRang\"):"
selected true
xpos 43934
ypos 296199
addUserKnob {20 user}
addUserKnob {4 type l Type t "- default: Creates a simple pulse.\n\n- even: Creates pulses on even numbers on the frame range.\n\n- odd: Creates pulses on odd numbers on the frame range.\n\n- multiple of X: Creates pulses on frames multiples of the number introduced.\n\n- every X frames: Creates pulses that starts on the current frame and repeats every X frames. X is the number introduced.\n\n- Custom: Creates pulses on selected frames.\n" M {default even odd "multiple of X" "every X frames" "Custom frames" "" "" "" "" "" "" "" "" "" ""}}
type "Custom frames"
addUserKnob {1 expression l " X=" t "Write a number here" -STARTLINE}
addUserKnob {22 addFrame l "Add Frame" t "Add current frame to custom pulses" -STARTLINE T "a = nuke.thisNode()\nb = str(nuke.frame())\n\n\n# Split the string into individual numbers\nframes_list = a\['expression'].getValue().split()\n\n# Iterate through the list of numbers and sort them\nif b not in frames_list:\n frames_list.append(b)\n sorted_list = sorted(frames_list, key=lambda x: int(x))\n sorted_string = ' '.join(sorted_list)\n a\['expression'].setValue(sorted_string)"}
addUserKnob {26 ""}
addUserKnob {7 hValue l "Higher value" t "This is the pulse value on his higher point"}
hValue 1
addUserKnob {7 length l "H Length" t "This is the number of frames with higher value." -STARTLINE R 0 10}
length 1
addUserKnob {7 lValue l "Lower value" t "This is the lower value (baseline) of the pulse."}
addUserKnob {7 hlSpacing l "H/L Spacing" t "This is the number of frames between the higher and lower values." -STARTLINE R 1 10}
hlSpacing 1
addUserKnob {6 apply l Apply t "Check to apply the pulse baseline value. if unchecked, only higher value keyframes will be taken into consideration." -STARTLINE}
apply true
addUserKnob {4 interpolation l Interpolation t "Interpolate keyframes with one of these nuke interpolations" M {Smooth Constant Linear Catmull-Rom Cubic "" "" "" "" "" ""}}
interpolation Constant
addUserKnob {6 frameRng l "Frame Range" t "Check for using your own frame range." +STARTLINE}
addUserKnob {3 startFrame l "" -STARTLINE +DISABLED}
startFrame 1001
addUserKnob {3 endFrame l "" -STARTLINE +DISABLED}
endFrame 1060
addUserKnob {22 generatePulse l Generate! T "import re\n\n#Set the interpolation value on a curve\ndef setInterpolation(animcurve, interpolation):\n if interpolation == 0:\n for k in animcurve:\n k.interpolation = nuke.SMOOTH\n elif interpolation == 1:\n for k in animcurve:\n k.interpolation = nuke.CONSTANT\n elif interpolation == 2:\n for k in animcurve:\n k.interpolation = nuke.LINEAR\n elif interpolation == 3:\n for k in animcurve:\n k.interpolation = nuke.CATMULL_ROM\n elif interpolation == 4:\n for k in animcurve:\n k.interpolation = nuke.CUBIC\n\n#Set a Pulse on one frame.\ndef default(frame, hValue, lValue, hlSpacing, length, interpolation):\n for num in range(0, length):\n v.setValueAt(hValue, frame + num)\n if thisN\['apply'].getValue():\n v.setValueAt(lValue, frame - hlSpacing)\n v.setValueAt(lValue, frame + length + hlSpacing - 1)\n \n#Set a Pulse on multiple frames of a given number\ndef multiple(frameRange, hValue, lValue, hlSpacing, interpolation, number):\n for f in range(frameRange\[0],frameRange\[1] + 1):\n if(f%number == 0):\n v.setValueAt(hValue, f)\n if thisN\['apply'].getValue():\n v.setValueAt(lValue, f - hlSpacing)\n if ((f+1)<(frameRange\[1] + 1)):\n v.setValueAt(lValue, f + hlSpacing)\n# else:\n# v.setValueAt(hValue, f)\n# if thisN\['apply'].getValue():\n# v.setValueAt(lValue, f)\n \n#Set a Pulse on odd frames of the frame Range \ndef odd(frameRange, hValue, lValue, interpolation):\n for f in range(frameRange\[0],frameRange\[1] + 1):\n if(f%2 != 0):\n v.setValueAt(hValue, f)\n elif thisN\['apply'].getValue():\n v.setValueAt(lValue, f)\n \n#Set a Pulse on every given number frames. Starting on any frame. Even out of the frame range. \ndef everyX(frame, frameRange, hValue, lValue, hlSpacing, interpolation, number, length):\n for f in range(frame, frameRange\[1] + 1, number):\n for num in range(0,length):\n v.setValueAt(hValue, f + num)\n if thisN\['apply'].getValue():\n v.setValueAt(lValue, f - hlSpacing)\n if((f + length) < (frameRange\[1] + 1)):\n v.setValueAt(lValue, f + length + hlSpacing -1)\n \ndef has_lower_difference(lst, threshold):\n for i in range(len(lst) - 1):\n if abs(int(lst\[i]) - int(lst\[i + 1])) < threshold:\n return True\n return False\n \n \n#Get project and nuke variables\nthisN = nuke.thisNode()\np = re.compile('^-?\[0-9]+\$')\n# Define a regular expression pattern to match numbers and spaces only\npattern = r'^\[0-9\\s]+\$'\nn = nuke.Root()\nframeRng = \[]\nprint (n.firstFrame(), thisN\['startFrame'].getValue(), thisN\['endFrame'].getValue())\nif (thisN\['frameRng'].getValue() == 1):\n frameRng.append(int(thisN\['startFrame'].getValue()))\n frameRng.append(int(thisN\['endFrame'].getValue()))\nelse:\n frameRng.append(n.firstFrame())\n frameRng.append(n.lastFrame())\nfr = nuke.frame()\n\n#Get Pulse information\nhVal = thisN\['hValue'].getValue()\nlVal = thisN\['lValue'].getValue()\nhLSpacingVal = thisN\['hlSpacing'].getValue()\nl = int(thisN\['length'].getValue())\ninter = thisN\['interpolation'].getValue()\nt = thisN\['type'].getValue()\n\n#Set expression\nexpr = 0\nif (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n expr = int(thisN\['expression'].getValue())\n \nif t == 0:\n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n \n default(fr, hVal, lVal, hLSpacingVal, l, inter)\n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\"Frame \" + str(fr) + \"\\\\n High for \" + str(l) + \" frames\")\n\nelif t == 1:\n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, 1, inter,2)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\" even frames\")\n \nelif t == 2:\n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n \n odd(frameRng, hVal, lVal, inter)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\" odd frames\")\n\nelif t == 3:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, hLSpacingVal, inter, expr)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\"frames multiple of \" + str(expr))\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type')\n \nelif t == 4:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n if (l < expr):\n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n if (thisN\['frameRng'].getValue() == 1):\n fr = int(thisN\['startFrame'].getValue())\n everyX(fr,frameRng, hVal, lVal, hLSpacingVal, inter, expr, l)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\"every \" + str(expr) + \" frames\" + \"\\\\n\" + \"from frame \" + str(fr) + \"\\\\n\" + \"High for \" + str(l) + \" frames\")\n else:\n nuke.message('Length of activity has to be lower than X')\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type') \nelif t == 5:\n if (thisN\['expression'].getValue() != \"\") and (re.search(pattern, (thisN\['expression'].getValue()))):\n # Split the string into individual numbers\n frames_list = thisN\['expression'].getValue().split()\n \n #Create and set Pulse\n nMult = nuke.nodes.Multiply()\n nMult.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = nMult\['value']\n v.setAnimated()\n\n # Iterate through the list of numbers and call the default function for each number\n for frames_str in frames_list:\n iframe = int(frames_str)\n default(iframe, hVal, lVal, hLSpacingVal, l, inter)\n \n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n nMult.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n nMult\['label'].setValue(\"Frames \" + thisN\['expression'].getValue() + \"\\\\n High for \" + str(l) + \" frames\")\n if (thisN\['apply'].getValue() == 1):\n if has_lower_difference(frames_list, hLSpacingVal+1):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H/L Spacing. Please check.\")\n else:\n if has_lower_difference(frames_list, l):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H length. Please check.\")\n else:\n nuke.message('Introduce a frame number or choose another type of Pulse type') \n " +STARTLINE}
addUserKnob {6 labelOn l "Display info" t "Displays information on node's label" -STARTLINE}
labelOn true
addUserKnob {26 "" +STARTLINE}
addUserKnob {22 replacePulse l "Replace selected" t "Select any multiply node and replace it with the new pulse." T "import re\n \ntry:\n modPulse = nuke.selectedNode()\n if modPulse.Class() == \"Multiply\":\n #Get project and nuke variables\n thisN = nuke.thisNode()\n n = nuke.Root()\n frameRng = \[]\n print (n.firstFrame(), thisN\['startFrame'].getValue(), thisN\['endFrame'].getValue())\n if (thisN\['frameRng'].getValue() == 1):\n frameRng.append(int(thisN\['startFrame'].getValue()))\n frameRng.append(int(thisN\['endFrame'].getValue()))\n else:\n frameRng.append(n.firstFrame())\n frameRng.append(n.lastFrame())\n fr = nuke.frame()\n \n #Get Pulse information\n hVal = thisN\['hValue'].getValue()\n lVal = thisN\['lValue'].getValue()\n hLSpacingVal = thisN\['hlSpacing'].getValue()\n l = int(thisN\['length'].getValue())\n inter = thisN\['interpolation'].getValue()\n t = thisN\['type'].getValue()\n \n # Define a regular expression pattern to match numbers and spaces only\n p = re.compile('^-?\[0-9]+\$')\n pattern = r'^\[0-9\\s]+\$'\n #Set expression\n expr = 0\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n expr = int(thisN\['expression'].getValue())\n \n if t == 0:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n print(\"t=0\")\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n v.setAnimated()\n \n default(fr, hVal, lVal, hLSpacingVal, l, inter)\n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\"Frame \" + str(fr) + \"\\\\n High for \" + str(l) + \" frames\")\n \n elif t == 1:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n \n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, 1, inter,2)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\" even frames\")\n \n elif t == 2:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n \n v.setAnimated()\n \n odd(frameRng, hVal, lVal, inter)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\" odd frames\")\n \n elif t == 3:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n \n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, hLSpacingVal, inter, expr)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\"frames multiple of \" + str(expr))\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type')\n \n elif t == 4:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n if (l < expr):\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n \n v.setAnimated()\n \n if (thisN\['frameRng'].getValue() == 1):\n fr = int(thisN\['startFrame'].getValue())\n everyX(fr,frameRng, hVal, lVal, hLSpacingVal, inter, expr, l)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\"every \" + str(expr) + \" frames\" + \"\\\\n\" + \"from frame \" + str(fr) + \"\\\\n\" + \"High for \" + str(l) + \" frames\")\n else:\n nuke.message('Length of activity has to be lower than X')\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type') \n elif t == 5:\n if (thisN\['expression'].getValue() != \"\") and (re.search(pattern, (thisN\['expression'].getValue()))):\n # Split the string into individual numbers\n frames_list = thisN\['expression'].getValue().split()\n \n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if v.isAnimated():\n # Reset animation\n v.clearAnimated()\n \n v.setAnimated()\n \n # Iterate through the list of numbers and call the default function for each number\n for frames_str in frames_list:\n iframe = int(frames_str)\n default(iframe, hVal, lVal, hLSpacingVal, l, inter)\n \n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n modPulse.setName('Pulse_On', uncollide=True)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(\"Frames \" + thisN\['expression'].getValue() + \"\\\\n High for \" + str(l) + \" frames\")\n if (thisN\['apply'].getValue() == 1):\n if has_lower_difference(frames_list, hLSpacingVal+1):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H/L Spacing. Please check.\")\n else:\n if has_lower_difference(frames_list, l):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H length. Please check.\")\n else:\n nuke.message('Introduce a frame number or choose another type of Pulse type')\n nuke.message(modPulse.name() + \"\\n updated!\")\n \nexcept Exception as error:\n pass\n " +STARTLINE}
addUserKnob {22 addPulse l "Add to selected" t "Add the pulse keyframes to any multiply node." -STARTLINE T "import re\n \ntry:\n modPulse = nuke.selectedNode()\n if modPulse.Class() == \"Multiply\":\n #Get project and nuke variables\n thisN = nuke.thisNode()\n n = nuke.Root()\n frameRng = \[]\n print (n.firstFrame(), thisN\['startFrame'].getValue(), thisN\['endFrame'].getValue())\n if (thisN\['frameRng'].getValue() == 1):\n frameRng.append(int(thisN\['startFrame'].getValue()))\n frameRng.append(int(thisN\['endFrame'].getValue()))\n else:\n frameRng.append(n.firstFrame())\n frameRng.append(n.lastFrame())\n fr = nuke.frame()\n \n #Get Pulse information\n hVal = thisN\['hValue'].getValue()\n lVal = thisN\['lValue'].getValue()\n hLSpacingVal = thisN\['hlSpacing'].getValue()\n l = int(thisN\['length'].getValue())\n inter = thisN\['interpolation'].getValue()\n t = thisN\['type'].getValue()\n \n # Define a regular expression pattern to match numbers and spaces only\n p = re.compile('^-?\[0-9]+\$')\n pattern = r'^\[0-9\\s]+\$'\n #Set expression\n expr = 0\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n expr = int(thisN\['expression'].getValue())\n \n if t == 0:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n print(\"t=0\")\n v = modPulse\['value']\n # Check if the knob is animated\n\n if not(v.isAnimated()):\n v.setAnimated()\n \n default(fr, hVal, lVal, hLSpacingVal, l, inter)\n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \"Frame \" + str(fr) + \"\\\\n High for \" + str(l) + \" frames\")\n \n elif t == 1:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if not(v.isAnimated()):\n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, 1, inter,2)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \" even frames\")\n \n elif t == 2:\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if not(v.isAnimated()):\n v.setAnimated()\n \n odd(frameRng, hVal, lVal, inter)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \" odd frames\")\n \n elif t == 3:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n #Create and set Pulse\n #modPulse = nuke.nodes.Multiply()\n #modPulse.setXYpos(thisN.xpos()+100,thisN.ypos()+50)\n v = modPulse\['value']\n # Check if the knob is animated\n if not(v.isAnimated()):\n v.setAnimated()\n \n multiple(frameRng, hVal, lVal, hLSpacingVal, inter, expr)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \"frames multiple of \" + str(expr))\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type')\n \n elif t == 4:\n if (thisN\['expression'].getValue() != \"\") and p.match(thisN\['expression'].getValue()):\n if (int(thisN\['expression'].getValue()) != 1): \n if ((hLSpacingVal*2) <= expr):\n if (l < expr):\n #Create and set Pulse\n v = modPulse\['value']\n # Check if the knob is animated\n if not(v.isAnimated()):\n v.setAnimated()\n \n if (thisN\['frameRng'].getValue() == 1):\n fr = int(thisN\['startFrame'].getValue())\n everyX(fr,frameRng, hVal, lVal, hLSpacingVal, inter, expr, l)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \"every \" + str(expr) + \" frames\" + \"\\\\n\" + \"from frame \" + str(fr) + \"\\\\n\" + \"High for \" + str(l) + \" frames\")\n else:\n nuke.message('Length of activity has to be lower than X')\n else:\n nuke.message('For this multiple, you need to decrease the H/L Spacing value.')\n else:\n nuke.message('Multiple has to be higher than 1')\n else:\n nuke.message('Introduce a number X or choose another type of Pulse type') \n elif t == 5:\n if (thisN\['expression'].getValue() != \"\") and (re.search(pattern, (thisN\['expression'].getValue()))):\n # Split the string into individual numbers\n frames_list = thisN\['expression'].getValue().split()\n \n #Create and set Pulse\n v = modPulse\['value']\n\n # Check if the knob is animated\n if not(v.isAnimated()):\n v.setAnimated()\n \n # Iterate through the list of numbers and call the default function for each number\n for frames_str in frames_list:\n iframe = int(frames_str)\n default(iframe, hVal, lVal, hLSpacingVal, l, inter)\n \n animC = v.animation(0).keys()\n setInterpolation(animC, inter)\n if (thisN\['labelOn'].getValue() == 1):\n modPulse\['label'].setValue(modPulse\['label'].getValue() + \".\\nAdded\" + \"Frames \" + thisN\['expression'].getValue() + \"\\\\n High for \" + str(l) + \" frames\")\n if (thisN\['apply'].getValue() == 1):\n if has_lower_difference(frames_list, hLSpacingVal+1):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H/L Spacing. Please check.\")\n else:\n if has_lower_difference(frames_list, l):\n nuke.message(\"Keyframes may OVERLAP! \\n\\n The result might not be the intended one. \\n\\n The list has frames with a lower difference than the H length. Please check.\")\n else:\n nuke.message('Introduce a frame number or choose another type of Pulse type')\n nuke.message(modPulse.name() + \"\\n updated!\")\n \nexcept Exception as error:\n pass\n "}
addUserKnob {26 _1 l "" +STARTLINE}
addUserKnob {26 version_author l "" t "v1.3 update:\nAdd Replace selected and Add pulse to seleced button" +STARTLINE T "
MF_PulseGenerator v1.3 - 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 pulse you want to create.\n\n - default: Creates a one event pulse.\n\n - even: Creates a pulse on even numbers on the frame range.\n\n - odd: Creates a pulse on odd numbers on the frame range.\n\n - multiple of X: Creates a pulse on frames multiples of the number introduced.\n\n - every X frames: Creates a pulse that starts on the current frame \n and repeats every X frames. X is the number introduced.\n\n - custom: Creates pulses on specified frames. Use \"Add frame\" button to add the current frame.\n Keyframes will overide previous frames if they're too close to each other. \n\n2.- Set the higher value of the pulse.\n\n3.- Set the number of frames that the pulse is on a high value. (H Length)\n\n4.- Set the lower value of the pulse. Check Apply to use this setting.\n\n5.- Select the H/L spacing (By default 1). This is the number of frames between the lower and the higher values.\n\n6.- Select the type of interpolation you want on the keyframes.\n\n7.- Select a Frame Range. By default, it will get the project settings frame range.\n\n8.- Press the \"Generate!\" button."}
}