-
Notifications
You must be signed in to change notification settings - Fork 5
/
kmfx_keyframeVisibility.py
70 lines (58 loc) · 2.71 KB
/
kmfx_keyframeVisibility.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import fx
from fx import *
from tools.objectIterator import getObjects
fx.prefs.add("KMFX_Load.Keyframe Visibility", True)
class KMFXkeyframeVisibility(Action):
"""Creates keyframes without clicking on the visibility icon"""
def __init__(self):
if fx.prefs["KMFX_Load.Keyframe Visibility"] is True:
Action.__init__(self, "KMFX|Keyframe Visibility")
def available(self):
shapes = getObjects(selection(), types=[Shape])
assert len(shapes) > 0, "There must be one or more selected shapes"
def execute(self, **kwargs):
shapes = getObjects(selection(), types=[Shape])
optype = kwargs["mode"] if "mode" in kwargs.keys() else "default"
beginUndo("Keyframe Visibility ON/OFF")
node = activeNode()
session = node.session
startFrame = session.startFrame
actualframe = player.frame
wasConstant = False
for shape in shapes:
opacity = shape.property("opacity")
if opacity.constant:
opacity.constant = False
wasConstant = True
if optype == "default":
if opacity.getValue(actualframe) > 0:
opacity.setValue(0, actualframe)
else:
opacity.setValue(100, actualframe)
if wasConstant and actualframe != 0:
editor = PropertyEditor(opacity)
editor.deleteKey(0)
editor.execute()
if optype == "singleframe":
if actualframe not in (0, session.duration):
if opacity.getValue(actualframe) > 0:
opacity.setValue(0, actualframe-1)
opacity.setValue(100, actualframe)
opacity.setValue(0, actualframe+1)
if actualframe != 1 and wasConstant:
editor = PropertyEditor(opacity)
editor.deleteKey(0)
editor.execute()
elif actualframe == 0:
if opacity.getValue(actualframe) > 0:
opacity.setValue(100, actualframe)
opacity.setValue(0, actualframe+1)
elif actualframe == session.duration:
if opacity.getValue(actualframe) > 0:
opacity.setValue(0, actualframe-1)
opacity.setValue(100, actualframe)
editor = PropertyEditor(opacity)
editor.deleteKey(0)
editor.execute()
endUndo()
addAction(KMFXkeyframeVisibility())