Skip to content

Instantly share code, notes, and snippets.

@BenMcEwan
Last active July 4, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BenMcEwan/023db72d04321fdafaf2cd89e38cad00 to your computer and use it in GitHub Desktop.
Save BenMcEwan/023db72d04321fdafaf2cd89e38cad00 to your computer and use it in GitHub Desktop.
# --------------------------------------------------------------
# QuickKeys.py
# Version: 2.0.0
# Last Updated: October 18th, 2018
# --------------------------------------------------------------
# --------------------------------------------------------------
# USAGE:
#
# Press 'Ctrl+,' to set an 'on keyframe' (current frame on, previous frame off).
# Press 'Ctrl+.' to set an 'off keyframe' (current frame on, next frame off).
# Press 'Ctrl+/' to set an 'on/off range', with control to fade over a number of frames
# --------------------------------------------------------------
import nuke
def qk(type):
n = nuke.selectedNode()
knob = "mix"
curFrame = nuke.frame()
dict = {'Switch':'which','Dissolve':'which','Roto':'opacity','RotoPaint':'opacity'}
for x in dict:
if n.Class() == x:
knob = dict[x]
if type == "range":
p = nuke.Panel( 'Quick Keys' )
p.addSingleLineInput('First Frame', '1001')
p.addSingleLineInput('Last Frame', '1099')
p.addSingleLineInput('Fade', '0')
if not p.show():
return
inFrame = float(p.value('First Frame'))
outFrame = float(p.value('Last Frame'))
fadeValue = float(p.value('Fade'))
n[knob].setAnimated(0)
animKnob = n[knob].animations()[0]
animKnob.setKey(inFrame,1)
animKnob.setKey((inFrame-1-fadeValue),0)
animKnob.setKey(outFrame,1)
animKnob.setKey((outFrame+1+fadeValue),0)
elif type == "on":
n[knob].setAnimated(0)
animKnob = n[knob].animations()[0]
animKnob.setKey(curFrame, 1)
animKnob.setKey((curFrame-1),0)
elif type == "off":
n[knob].setAnimated(0)
animKnob = n[knob].animations()[0]
animKnob.setKey(curFrame, 1)
animKnob.setKey((curFrame+1),0)
else:
return
nuke.menu('Nuke').addCommand('Edit/Quick Keys/On', 'quickKeys.qk("on")', "meta+,")
nuke.menu('Nuke').addCommand('Edit/Quick Keys/Off', 'quickKeys.qk("off")', "meta+.")
nuke.menu('Nuke').addCommand('Edit/Quick Keys/Range', 'quickKeys.qk("range")', "meta+/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment