-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathexpressions.py
More file actions
27 lines (24 loc) · 1.17 KB
/
expressions.py
File metadata and controls
27 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from __future__ import print_function
import nuke
# Bake all knobs with expressions to keyframes
nuke.menu('Nuke').addCommand('Edit/Node/Bake Expressions', 'expressions.bake(nuke.selectedNodes(), nuke.root().firstFrame(), nuke.root().lastFrame())', 'ctrl+alt+meta+shift+b')
def bake(nodes, start, end):
for node in nodes:
for knob in list(node.knobs().values()):
if isinstance(knob, nuke.Link_Knob):
knob = knob.getLinkedKnob()
if knob.hasExpression():
if knob.singleValue():
array_size = 1
else:
array_size = knob.arraySize()
for index in range(array_size):
if knob.hasExpression(index):
anim = knob.animation(index)
anim_keys = []
for frame in range(start, end + 1):
anim_keys.append(nuke.AnimationKey(frame, anim.evaluate(frame)))
anim.addKey(anim_keys)
knob.setExpression("curve", index)
if anim.constant():
knob.clearAnimated(index)