-
Notifications
You must be signed in to change notification settings - Fork 13
/
search_functions.py
186 lines (166 loc) · 7.54 KB
/
search_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import bpy
armature=[]
mesh_deform=[]
surface_deform=[]
armature_name=[]
mesh_deform_name=[]
surface_deform_name=[]
lattices=[]
boneshapes=[]
###### Search name of MDef_cage #####
def mdef_search(type):
mdef_cage_objects = []
mdef_cage_names = []
sdef_cage_objects = []
sdef_cage_names = []
arm = bpy.context.active_object.name
for ob in bpy.data.objects:
if hasattr(ob,'modifiers'):
for ob_m in ob.modifiers:
if type == 'MESH_DEFORM':
if ob_m.type == type:
if hasattr(ob.modifiers[ob_m.name], 'object') and hasattr(ob.modifiers[ob_m.name].object, 'name'):
cage = ob.modifiers[ob_m.name].object
if hasattr(cage, 'modifiers'):
for mod in cage.modifiers:
if mod.type == 'ARMATURE':
if mod.object.name == arm:
if bpy.data.objects.get(ob.modifiers[ob_m.name].object.name) not in mdef_cage_objects:
mdef_cage_objects.append(bpy.data.objects.get(ob.modifiers[ob_m.name].object.name))
mdef_cage_names.append(ob.modifiers[ob_m.name].object.name)
return mdef_cage_objects , mdef_cage_names
for ob in bpy.data.objects:
if hasattr(ob,'modifiers'):
for ob_m in ob.modifiers:
if type == 'SURFACE_DEFORM':
if ob_m.type == type:
if hasattr(ob.modifiers[ob_m.name], 'target') and hasattr(ob.modifiers[ob_m.name].target, 'name'):
cage = ob.modifiers[ob_m.name].target
if hasattr(cage, 'modifiers'):
for mod in cage.modifiers:
if mod.type == 'ARMATURE':
if mod.object.name == arm:
if bpy.data.objects.get(ob.modifiers[ob_m.name].target.name) not in sdef_cage_objects:
sdef_cage_objects.append(bpy.data.objects.get(ob.modifiers[ob_m.name].target.name))
sdef_cage_objects.append(ob.modifiers[ob_m.name].target.name)
return sdef_cage_objects , sdef_cage_names
###### Search objets with modifiers #####
def search_mod(type):
arm = bpy.context.active_object.name
#Clean Variables
mdef_cage_name =[]
sdef_cage_name = []
surface_deform = []
mesh_deform = []
armature = []
surface_deform_name = []
mesh_deform_name = []
armature_name = []
mdef_cage_name = mdef_search('MESH_DEFORM')
sdef_cage_name = mdef_search('SURFACE_DEFORM')
for ob in bpy.data.objects:
if hasattr(ob,'modifiers'):
for ob_m in ob.modifiers:
if ob_m.type == type:
if hasattr(ob.modifiers[ob_m.name], 'object') and hasattr(ob.modifiers[ob_m.name].object, 'name'):
if ob.modifiers[ob_m.name].object in mdef_cage_name[0]:
if ob not in mesh_deform:
mesh_deform.append(ob)
mesh_deform_name.append(ob.name)
if hasattr(ob.modifiers[ob_m.name], 'object') and hasattr(ob.modifiers[ob_m.name].object, 'name'):
if ob.modifiers[ob_m.name].object.name == arm:
if ob not in armature:
armature.append(ob)
armature_name.append(ob.name)
if hasattr(ob.modifiers[ob_m.name],'target') and hasattr(ob.modifiers[ob_m.name].target, 'name'):
if ob.modifiers[ob_m.name].target in sdef_cage_name[0]:
if ob not in surface_deform:
surface_deform.append(ob)
surface_deform_name.append(ob.name)
if type == "ARMATURE":
return armature, armature_name
if type == "MESH_DEFORM":
return mesh_deform, mesh_deform_name
if type =="SURFACE_DEFORM":
return surface_deform, surface_deform_name
########### Toggle link/unlink objets with modifiers in BlenRig_temp #######
def blenrig_temp(type,lnk = True):
if lnk:
if type == "ARMATURE":
link_objects(search_mod(type)[0])
elif type == "MESH_DEFORM":
link_objects(search_mod(type)[0])
elif type == "SURFACE_DEFORM":
link_objects(search_mod(type)[0])
elif not lnk:
if type == "ARMATURE":
unlink_objects(search_mod(type)[0])
elif type == "MESH_DEFORM":
unlink_objects(search_mod(type)[0])
elif type == "SURFACE_DEFORM":
unlink_objects(search_mod(type)[0])
###### link objets in BlenRig_temp #####
def link_objects(objects):
temp_collection = bpy.data.collections.get("BlenRig_temp")
if objects:
if bpy.context.scene.collection.children.find("BlenRig_temp") == -1:
if temp_collection:
bpy.context.scene.collection.children.link(temp_collection)
else:
temp_collection = bpy.data.collections.new("BlenRig_temp")
bpy.context.scene.collection.children.link(temp_collection)
for ob in objects:
if not bpy.context.scene.collection.children[temp_collection.name].objects.get(ob.name):
temp_collection.objects.link(ob)
###### Unlink objets in BlenRig_temp #####
def unlink_objects(objects):
temp_collection = bpy.data.collections.get("BlenRig_temp")
if objects:
if bpy.context.scene.collection.children.get('BlenRig_temp'):
for ob in objects:
try:
temp_collection.objects.unlink(ob)
except:
pass
objects.clear()
if len(bpy.data.collections['BlenRig_temp'].objects) < 1:
bpy.context.scene.collection.children.unlink(temp_collection)
####### Search objets parent with biped_blenrig (lattices) ######
def search_parent():
arm = bpy.context.active_object.name
for ob in bpy.data.objects:
if hasattr(ob,'parent') and hasattr(ob.parent, 'name'):
if not ob.name.startswith('cs_') and ob.parent.name == arm:
lattices.append(ob)
return lattices
####### Search BoneShapes #####
def search_boneshapes():
arm = bpy.context.active_object.name
for ob in bpy.data.objects:
if hasattr(ob,'parent'):
if ob.name.startswith('cs_'):
boneshapes.append(ob)
return boneshapes
########### Toggle linking objets BoneShapes in BlenRig_temp #######
def blenrig_temp_boneshapes(lnk = True):
if lnk:
link_objects(search_boneshapes())
elif not lnk:
unlink_objects(search_boneshapes())
########### Toggle linking objets Lattices and Parenting objects in BlenRig_temp #######
def blenrig_temp_parent(lnk = True):
if lnk:
link_objects(search_parent())
elif not lnk:
unlink_objects(search_parent())
########### Toggle linking MDef_Cage in BlenRig_temp #######
def blenrig_temp_mdef_cage(lnk = True):
if lnk:
link_objects(mdef_search('MESH_DEFORM')[0])
elif not lnk:
unlink_objects(mdef_search('MESH_DEFORM')[0])
def blenrig_temp_sdef_cage(lnk = True):
if lnk:
link_objects(mdef_search('SURFACE_DEFORM')[0])
elif not lnk:
unlink_objects(mdef_search('SURFACE_DEFORM')[0])