-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.py
113 lines (102 loc) · 4.08 KB
/
functions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import bpy
# return selected object
def getSelectedObjects(scene):
object_list = []
for obj in scene.objects:
if obj.select_get():
object_list.append(obj)
return object_list
# return selected armature active bones fcurves
def getSelectedBonesFCurves(object):
curves_list = []
if object.animation_data:
try:
if object.type == 'ARMATURE':
bones_list = []
for bone in object.data.bones:
if bone.select:
bones_list.append(bone.name)
for curve in object.animation_data.action.fcurves:
if curve.select:
if curve.data_path.startswith("pose.bones"):
for bone in bones_list:
if bone in curve.data_path:
curves_list.append(curve)
except AttributeError: pass
return curves_list
# return all armature active bones fcurves
def getFCurvesFromBone(bone, object):
curves_list = []
try:
for curve in object.animation_data.action.fcurves:
if curve.data_path.startswith("pose.bones"):
if bone.name in curve.data_path:
curves_list.append(curve)
except AttributeError: pass
return curves_list
# return selected objects fcurves
def getSelectedFCurves(object):
curves_list = []
if object.animation_data:
try:
for curve in object.animation_data.action.fcurves:
if curve.select and not curve.data_path.startswith("pose.bones"):
curves_list.append(curve)
except AttributeError: pass
return curves_list
# return objects fcurves
def getFCurves(object):
curves_list = []
if object.animation_data :
try:
for curve in object.animation_data.action.fcurves:
if not curve.data_path.startswith("pose.bones"):
curves_list.append(curve)
except AttributeError: pass
return curves_list
# get props from modifiers
def getModifierProperties(modifier):
properties_list = []
for prop in modifier.bl_rna.properties:
if not prop.is_readonly:
properties_list.append(prop)
return properties_list
# redraw context areas
def redrawContextAreas(context):
for area in context.screen.areas:
area.tag_redraw()
# set props from dataset
def setPropertiesFromDataset(datasetin, datasetout):
wm = bpy.context.window_manager
for prop in datasetin.bl_rna.properties:
if not prop.is_readonly and prop.identifier != 'name':
try:
if wm.fcurvehelper_debug: print("FCurveHelper --- setting %s to %s" % (prop.identifier, str(getattr(datasetout, prop.identifier)))) ###debug
setattr(datasetout, '%s' % prop.identifier, getattr(datasetin, prop.identifier))
#handle generator array error
except ValueError:
if wm.fcurvehelper_debug: print("FCurveHelper --- setting %s array after ValueError" % prop.identifier) ###debug
propin = getattr(datasetin, prop.identifier)
propout = getattr(datasetout, prop.identifier)
idx = -1
for n in propin:
idx += 1
propout[idx] = n
except (KeyError, AttributeError):
if wm.fcurvehelper_debug: print("FCurveHelper --- %s not set, KeyError" % prop.identifier) ###debug
pass
# returning proper f curve from object, index and array
def returnFCurve(object, data_path, array_index):
if object.animation_data:
try:
for curve in object.animation_data.action.fcurves:
if curve.data_path == data_path and curve.array_index == array_index:
return curve
except AttributeError:
pass
# get active modifier from curve
def getActiveModifier(curve):
if curve.modifiers:
for mod in curve.modifiers:
if mod.active:
return mod