Nuke Tips – Disable Node Using Expression

nuke_disable_node_header

Time to cripple I mean disable node using expression

There are times when you have a Nuke script that feature really heavy nodes that affects specific frame range and you need it to automatically disable at specific frame range after it has done its job.

Problem here is that the process is not automated and Nuke will keep on processing the heavy nodes even if it doesn’t contribute to the overall rendering outside of the intended frame range.

You can easily use expression at the Disable knob to ensure the nodes get disable after meeting the condition. It doesn’t have to be a CPU/GPU heavy nodes, you can use the expression to toggle any nodes when it should be disable.

Although do take note that the default expression uses TCL. I’m unsure if you can use Python expression to achieve the same result but it should be not an issue as Nuke support Python. You just need to get the correct syntax and declaration for the respective script language.

Example 1 (Disabling after or before a frame)

Let’s say you need to disable from Frame 80 onwards. Add frame > 79 to the Disable knob expression. Nuke will automatically disable the node from Frame 80 onwards. You can also use frame < x to disable the node before x (where x is the frame number).

Example 2 (Disabling at specific frame range)

You need to disable a particular frame range. This can be done using inRange ( frame, x, y ) where x and y is the start and end frame respectively. So inRange ( frame, 20, 30) means the node will get disable from frame 20 to 30.

Sample Script

Copy and paste the following script into Nuke to see three quick samples that I created.

 set cut_paste_input [stack 0]
version 9.0 v5b17
ColorWheel {
 inputs 0
 gamma 0.45
 name ColorWheel1
 selected true
 xpos 335
 ypos -165
}
Transform {
 rotate {{-(frame)}}
 center {1024 778}
 name Transform1
 label "The wheel rotation\nis driven by\nexpression"
 note_font "Verdana Bold"
 note_font_size 20
 note_font_color 0xffffffff
 selected true
 xpos 335
 ypos -62
}
set N4c29800 [stack 0]
Dot {
 name Dot1
 selected true
 xpos 236
 ypos -21
}
set N4b80400 [stack 0]
GodRays {
 channels rgba
 scale 1.7
 center {{curve x1 -735 x100 2360} {curve x1 2055 x100 2040}}
 name GodRays1
 label "No expression\nfor Disable knob"
 selected true
 xpos 202
 ypos 145
}
push $N4c29800
clone node4b80000|Merge2|7276 Merge2 {
 inputs 2
 operation plus
 mix {{curve x60 1 x70 0}}
 name Merge1
 selected true
 xpos 335
 ypos 158
}
set C4b80000 [stack 0]
push $N4b80400
Dot {
 name Dot2
 selected true
 xpos 99
 ypos -21
}
GodRays {
 channels rgba
 scale 1.7
 center {{curve x1 -735 x100 2360} {curve x1 2055 x100 2040}}
 name GodRays2
 label "Disable from \nframe 71 onwards"
 note_font Verdana
 selected true
 xpos 65
 ypos 250
 disable {{"frame > 70"}}
}
push $N4c29800
Dot {
 name Dot4
 selected true
 xpos 509
 ypos -21
}
clone $C4b80000 {
 inputs 2
 xpos 475
 ypos 261
 selected true
}
push $cut_paste_input
Roto {
 output alpha
 curves {{{v x3f99999a}
  {f 0}
  {n
   {layer Root
    {f 2097152}
    {t x44800000 x44428000}
    {a pt1x 0 pt1y 0 pt2x 0 pt2y 0 pt3x 0 pt3y 0 pt4x 0 pt4y 0 ptex00 0 ptex01 0 ptex02 0 ptex03 0 ptex10 0 ptex11 0 ptex12 0 ptex13 0 ptex20 0 ptex21 0 ptex22 0 ptex23 0 ptex30 0 ptex31 0 ptex32 0 ptex33 0 ptof1x 0 ptof1y 0 ptof2x 0 ptof2y 0 ptof3x 0 ptof3y 0 ptof4x 0 ptof4y 0 pterr 0 ptrefset 0 ptmot x40800000 ptref 0}
    {curvegroup Bezier4 512 bezier
     {{cc
       {f 8192}
       {px x41e80000
        {0 0}
        {x44c59d31 x44316b84}
        {0 0}
        {0 0}
        {x44e5876e x44432d0d}
        {0 0}
        {0 0}
        {x44dfa314 x445ca6e8}
        {0 0}
        {0 0}
        {x44ccfaa1 x445679da}
        {0 0}
        {0 0}
        {x44c98ac2 x446775c1}
        {0 0}
        {0 0}
        {x44d5d128 x44730a3c}
        {0 0}
        {0 0}
        {x44d1e397 x448265e3}
        {0 0}
        {0 0}
        {x44c51f7e x447dd915}
        {0 0}
        {0 0}
        {x44c0b43b x4488f5c2}
        {0 0}
        {0 0}
        {x44cfecce x448f85a1}
        {0 0}
        {0 0}
        {x44c793f9 x44998ed9}
        {0 0}
        {0 0}
        {x44b1f95a x4492fef9}
        {0 0}}}     idem}
     {tx x41e80000 x44d71d8a x448ed89e}
     {a osw x41200000 osf 0 str 1 spx x44800000 spy x44428000 sb 1 ltn x41e80000 ltm x41e80000 tt x40800000}}
    {curvegroup Bezier3 512 bezier
     {{cc
       {f 8192}
       {px x41e80000
        {0 0}
        {x4476f230 x448ba979}
        {0 0}
        {0 0}
        {x448e9f3d x44904b43}
        {0 0}
        {0 0}
        {x449ae5a3 x446b51ea}
        {0 0}
        {0 0}
        {x449dd7d0 x4493c49b}
        {0 0}
        {0 0}
        {x44ac92b2 x4496db22}
        {0 0}
        {0 0}
        {x44a8276e x444d3644}
        {0 0}
        {0 0}
        {x44ccfaa1 x4415a0c4}
        {0 0}
        {0 0}
        {x44b6e24f x440eae13}
        {0 0}
        {0 0}
        {x449dd7d0 x4434820b}
        {0 0}
        {0 0}
        {x44a7a9bc x43f5374a}
        {0 0}
        {0 0}
        {x44996c8d x43e8dd2c}
        {0 0}}}     idem}
     {tx x41e80000 x44ada2e9 x446d1746}
     {a osw x41200000 osf 0 str 1 spx x44800000 spy x44428000 sb 1 ltn x41e80000 ltm x41e80000 tt x40800000}}
    {curvegroup Bezier2 512 bezier
     {{cc
       {f 8192}
       {px x41e80000
        {0 0}
        {x44218316 x4458cabf}
        {0 0}
        {0 0}
        {x4443e1ce x445be146}
        {0 0}
        {0 0}
        {x445785a5 x44197ced}
        {0 0}
        {0 0}
        {x4480dfc0 x441c9373}
        {0 0}
        {0 0}
        {x446e1ba9 x445fbd6f}
        {0 0}
        {0 0}
        {x4481db24 x446524dc}
        {0 0}
        {0 0}
        {x44928cce x43ea6870}
        {0 0}
        {0 0}
        {x444db3b9 x43e5c6a6}
        {0 0}}}     idem}
     {tx x41e80000 x44792000 x44440000}
     {a osw x41200000 osf 0 str 1 spx x44800000 spy x44428000 sb 1 ltn x41e80000 ltm x41e80000 tt x40800000}}
    {curvegroup Bezier1 512 bezier
     {{cc
       {f 8192}
       {px x41e80000
        {0 0}
        {x42e78952 x445ca6e8}
        {0 0}
        {0 0}
        {x4365ae22 x438dc49a}
        {0 0}
        {0 0}
        {x43daee9e x438f4fdd}
        {0 0}
        {0 0}
        {x43afb95f x44251167}
        {0 0}
        {0 0}
        {x4417b12a x43a04bc4}
        {0 0}
        {0 0}
        {x443c06ab x43c24394}
        {0 0}
        {0 0}
        {x43f66d98 x44749580}
        {0 0}
        {0 0}
        {x43b98b4a x446c178c}
        {0 0}
        {0 0}
        {x43fc51f2 x44166665}
        {0 0}
        {0 0}
        {x437951f8 x446775c1}
        {0 0}}}     idem}
     {tx x41e80000 x43f26666 x44274ccd}
     {a osw x41200000 osf 0 str 1 spx x44800000 spy x44428000 sb 1 ltn x41e80000 ltm x41e80000 tt x40800000}}}}}}
 toolbox {selectAll {
  { selectAll str 1 ssx 1 ssy 1 sf 1 }
  { createBezier str 1 ssx 1 ssy 1 sf 1 sb 1 tt 4 }
  { createBezierCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { createBSpline str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { createEllipse str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { createRectangle str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { createRectangleCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { brush str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { eraser src 2 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { clone src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { reveal src 3 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { dodge src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { burn src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { blur src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { sharpen src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
  { smear src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
} }
 toolbar_brush_hardness 0.200000003
 toolbar_source_transform_scale {1 1}
 toolbar_source_transform_center {1024 778}
 colorOverlay {0 0 0 0}
 lifetime_type "all frames"
 lifetime_start 29
 lifetime_end 29
 motionblur_shutter_offset_type centred
 source_black_outside true
 name Roto1
 selected true
 xpos 1012
 ypos -25
}
Constant {
 inputs 0
 channels rgb
 color {1 0.156805 0 0}
 color_panelDropped true
 name Constant1
 selected true
 xpos 1128
 ypos -119
}
Copy {
 inputs 2
 from0 rgba.alpha
 to0 rgba.alpha
 name Copy1
 selected true
 xpos 1128
 ypos -25
}
Premult {
 name Premult1
 selected true
 xpos 1128
 ypos 66
}
ColorBars {
 inputs 0
 name ColorBars2
 selected true
 xpos 1340
 ypos -110
}
Merge2 {
 inputs 2
 name Merge2
 label "Disable using\ninRange"
 note_font "Verdana Bold"
 note_font_size 20
 note_font_color 0xffffffff
 selected true
 xpos 1340
 ypos 40
 disable {{"inrange (frame, 20, 40)"}}
}
Viewer {
 inputs 2
 frame 86
 frame_range 1-100
 name Viewer1
 selected true
 xpos 475
 ypos 456
}
StickyNote {
 inputs 0
 name StickyNote1
 label "The Disabled GodRays\nshould render slightly\nfaster compared to\nnon-disabled GodRays\nas Nuke still calculate the\nGodRays even though it is\nnot visible on screen after\nthe Merge mix is set to 0.\n"
 note_font Verdana
 note_font_size 14
 selected true
 xpos 564
 ypos 20
}
StickyNote {
 inputs 0
 name StickyNote2
 label Slow
 note_font "Verdana Bold"
 selected true
 xpos 384
 ypos 126
}
StickyNote {
 inputs 0
 name StickyNote3
 label Fast
 note_font "Verdana Bold Bold"
 selected true
 xpos 531
 ypos 230
}
ColorBars {
 inputs 0
 name ColorBars1
 selected true
 xpos -491
 ypos -105
}
Defocus {
 defocus {{curve x1 0 x80 100}}
 name Defocus1
 label "Disable from\nframe 80 onwards"
 note_font "Verdana Bold"
 note_font_size 20
 note_font_color 0xffffffff
 selected true
 xpos -491
 ypos 12
 disable {{"frame > 79"}}
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.