forked from katiemorrisfx/KMFX-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmfx_cyclePaintPresets.py
62 lines (42 loc) · 1.3 KB
/
kmfx_cyclePaintPresets.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
import fx,sys
from fx import *
fx.prefs.add("KMFX.Paint Presets maximum cycle", 4, min=2, max=10)
class KMFXcyclePaintPresets(Action):
"""You can cycle your paint presets with a keybind"""
def __init__(self,):
Action.__init__(self, "KMFX|Cycle Paint Presets")
def available(self):
node = fx.activeNode()
assert node != None and node.isType("PaintNode"), "Paint node not active"
def execute(self):
fx.beginUndo("Cycle_Paint_Presets")
direction=1
node = fx.activeNode()
num_presets = fx.prefs["KMFX.Paint Presets maximum cycle"]
if node.type == "PaintNode":
current = fx.paint.preset
if current < 0:
return
index = current
nextp = True
while nextp == True:
index = index + direction
# handle wraparound
if index < 0:
index = num_presets - 1
elif index >= num_presets:
index = 0
# avoid infinite loop if only one preset
if index == current:
break
# check for a preset
try:
preset = node.state["preset%d" % (index)]
fx.paint.preset = index
nextp = False
except:
# e = sys.exc_info()
# print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)
pass
fx.endUndo()
addAction(KMFXcyclePaintPresets())