Newer
Older
#====================== BEGIN GPL LICENSE BLOCK ======================
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#======================= END GPL LICENSE BLOCK ========================
from .utils import get_rig_type, MetarigError
from .utils import write_metarig, write_widget
from .utils import unique_name
from . import rig_lists
from . import generate
class DATA_PT_rigify_buttons(bpy.types.Panel):
bl_label = "Rigify Buttons"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
#bl_options = {'DEFAULT_OPEN'}
@classmethod
def poll(cls, context):
def draw(self, context):
C = context
layout = self.layout
obj = context.object
Campbell Barton
committed
id_store = C.window_manager
if obj.mode in {'POSE', 'OBJECT'}:
layout.operator("pose.rigify_generate", text="Generate")
WARNING = "Warning: Some features may change after generation"
show_warning = False
check_props = ['IK_follow', 'root/parent', 'FK_limb_follow', 'IK_Stretch']
for obj in bpy.data.objects:
if type(obj.data) != bpy.types.Armature:
continue
for bone in obj.pose.bones:
if bone.bone.layers[30] and (list(set(bone.keys()) & set(check_props))):
show_warning = True
break
if show_warning:
layout.label(text=WARNING, icon='ERROR')
elif obj.mode == 'EDIT':
# Build types list
Campbell Barton
committed
collection_name = str(id_store.rigify_collection).replace(" ", "")
Campbell Barton
committed
for i in range(0, len(id_store.rigify_types)):
id_store.rigify_types.remove(0)
for r in rig_lists.rig_list:
Campbell Barton
committed
a = id_store.rigify_types.add()
a.name = r
elif r.startswith(collection_name + '.'):
Campbell Barton
committed
a = id_store.rigify_types.add()
elif (collection_name == "None") and ("." not in r):
Campbell Barton
committed
a = id_store.rigify_types.add()
a.name = r
## Rig collection field
#row = layout.row()
Campbell Barton
committed
#row.prop(id_store, 'rigify_collection', text="Category")
# Rig type list
row = layout.row()
row.template_list("UI_UL_list", "rigify_types", id_store, "rigify_types", id_store, 'rigify_active_type')
props = layout.operator("armature.metarig_sample_add", text="Add sample")
props.metarig_type = id_store.rigify_types[id_store.rigify_active_type].name
Nathan Vegdahl
committed
class DATA_PT_rigify_layer_names(bpy.types.Panel):
bl_label = "Rigify Layer Names"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
Nathan Vegdahl
committed
def draw(self, context):
layout = self.layout
obj = context.object
Nathan Vegdahl
committed
# Ensure that the layers exist
Campbell Barton
committed
if 0:
for i in range(1 + len(arm.rigify_layers), 29):
arm.rigify_layers.add()
Campbell Barton
committed
else:
# Can't add while drawing, just use button
Campbell Barton
committed
layout.operator("pose.rigify_layer_init")
return
Nathan Vegdahl
committed
# UI
for i, rigify_layer in enumerate(arm.rigify_layers):
# note: rigify_layer == arm.rigify_layers[i]
Nathan Vegdahl
committed
if (i % 16) == 0:
col = layout.column()
if i == 0:
col.label(text="Top Row:")
else:
col.label(text="Bottom Row:")
if (i % 8) == 0:
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
col = layout.column()
if i != 28:
row = col.row(align=True)
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
#row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon)
row.prop(rigify_layer, "name", text="")
row.prop(rigify_layer, "row", text="UI Row")
icon = 'RADIOBUT_ON' if rigify_layer.set else 'RADIOBUT_OFF'
row.prop(rigify_layer, "set", text="", toggle=True, icon=icon)
row.prop(rigify_layer, "group", text="Bone Group")
else:
row = col.row(align=True)
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
# row.prop(arm, "layers", index=i, text="Layer %d" % (i + 1), toggle=True, icon=icon)
row1 = row.split(align=True).row(align=True)
row1.prop(rigify_layer, "name", text="")
row1.prop(rigify_layer, "row", text="UI Row")
row1.enabled = False
icon = 'RADIOBUT_ON' if rigify_layer.set else 'RADIOBUT_OFF'
row.prop(rigify_layer, "set", text="", toggle=True, icon=icon)
row.prop(rigify_layer, "group", text="Bone Group")
if rigify_layer.group == 0:
row.label(text='None')
else:
row.label(text=arm.rigify_colors[rigify_layer.group-1].name)
col = layout.column()
col.label(text="Reserved:")
# reserved_names = {28: 'Root', 29: 'DEF', 30: 'MCH', 31: 'ORG'}
reserved_names = {29: 'DEF', 30: 'MCH', 31: 'ORG'}
# for i in range(28, 32):
for i in range(29, 32):
row = col.row(align=True)
icon = 'RESTRICT_VIEW_OFF' if arm.layers[i] else 'RESTRICT_VIEW_ON'
row.prop(arm, "layers", index=i, text="", toggle=True, icon=icon)
row.label(text=reserved_names[i])
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
class DATA_OT_rigify_add_bone_groups(bpy.types.Operator):
bl_idname = "armature.rigify_add_bone_groups"
bl_label = "Rigify Add Standard Bone Groups"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
armature = obj.data
if not hasattr(armature, 'rigify_colors'):
return {'FINISHED'}
groups = ['Face', 'Face Primary', 'Face Secondary', 'FK', 'IK', 'Tweaks', 'Torso', 'Upper Body', 'Upper Spine']
themes = {'Face': 'THEME11', 'Face Primary': 'THEME01', 'Face Secondary': 'THEME09',
'FK': 'THEME04', 'IK': 'THEME01', 'Tweaks': 'THEME14',
'Torso': 'THEME03', 'Upper Body': 'THEME09', 'Upper Spine': 'THEME02'}
for g in groups:
if g in armature.rigify_colors.keys():
continue
armature.rigify_colors.add()
armature.rigify_colors[-1].name = g
id = int(themes[g][-2:]) - 1
armature.rigify_colors[-1].normal = bpy.context.user_preferences.themes[0].bone_color_sets[id].normal
armature.rigify_colors[-1].select = bpy.context.user_preferences.themes[0].bone_color_sets[id].select
armature.rigify_colors[-1].active = bpy.context.user_preferences.themes[0].bone_color_sets[id].active
return {'FINISHED'}
class DATA_OT_rigify_use_standard_colors(bpy.types.Operator):
bl_idname = "armature.rigify_use_standard_colors"
bl_label = "Rigify Get active/select colors from current theme"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
armature = obj.data
if not hasattr(armature, 'rigify_colors'):
return {'FINISHED'}
current_theme = bpy.context.user_preferences.themes.items()[0][0]
theme = bpy.context.user_preferences.themes[current_theme]
armature.rigify_selection_colors.select = theme.view_3d.bone_pose
armature.rigify_selection_colors.active = theme.view_3d.bone_pose_active
# for col in armature.rigify_colors:
# col.select = theme.view_3d.bone_pose
# col.active = theme.view_3d.bone_pose_active
return {'FINISHED'}
class DATA_OT_rigify_apply_selection_colors(bpy.types.Operator):
bl_idname = "armature.rigify_apply_selection_colors"
bl_label = "Rigify Apply user defined active/select colors"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
armature = obj.data
if not hasattr(armature, 'rigify_colors'):
return {'FINISHED'}
#current_theme = bpy.context.user_preferences.themes.items()[0][0]
#theme = bpy.context.user_preferences.themes[current_theme]
for col in armature.rigify_colors:
col.select = armature.rigify_selection_colors.select
col.active = armature.rigify_selection_colors.active
return {'FINISHED'}
class DATA_OT_rigify_bone_group_add(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_add"
bl_label = "Rigify Add Bone Group color set"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
armature = obj.data
if hasattr(armature, 'rigify_colors'):
armature.rigify_colors.add()
armature.rigify_colors[-1].name = unique_name(armature.rigify_colors, 'Group')
current_theme = bpy.context.user_preferences.themes.items()[0][0]
theme = bpy.context.user_preferences.themes[current_theme]
armature.rigify_colors[-1].normal = theme.view_3d.wire
armature.rigify_colors[-1].normal.hsv = theme.view_3d.wire.hsv
armature.rigify_colors[-1].select = theme.view_3d.bone_pose
armature.rigify_colors[-1].select.hsv = theme.view_3d.bone_pose.hsv
armature.rigify_colors[-1].active = theme.view_3d.bone_pose_active
armature.rigify_colors[-1].active.hsv = theme.view_3d.bone_pose_active.hsv
return {'FINISHED'}
class DATA_OT_rigify_bone_group_add_theme(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_add_theme"
bl_label = "Rigify Add Bone Group color set from Theme"
bl_options = {"REGISTER", "UNDO"}
theme = bpy.props.EnumProperty(items=(('THEME01', 'THEME01', ''),
('THEME02', 'THEME02', ''),
('THEME03', 'THEME03', ''),
('THEME04', 'THEME04', ''),
('THEME05', 'THEME05', ''),
('THEME06', 'THEME06', ''),
('THEME07', 'THEME07', ''),
('THEME08', 'THEME08', ''),
('THEME09', 'THEME09', ''),
('THEME10', 'THEME10', ''),
('THEME11', 'THEME11', ''),
('THEME12', 'THEME12', ''),
('THEME13', 'THEME13', ''),
('THEME14', 'THEME14', ''),
('THEME15', 'THEME15', ''),
('THEME16', 'THEME16', ''),
('THEME17', 'THEME17', ''),
('THEME18', 'THEME18', ''),
('THEME19', 'THEME19', ''),
('THEME20', 'THEME20', '')
),
name='Theme')
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
armature = obj.data
if hasattr(armature, 'rigify_colors'):
if self.theme in armature.rigify_colors.keys():
return {'FINISHED'}
armature.rigify_colors.add()
armature.rigify_colors[-1].name = self.theme
id = int(self.theme[-2:]) - 1
theme_color_set = bpy.context.user_preferences.themes[0].bone_color_sets[id]
armature.rigify_colors[-1].normal = theme_color_set.normal
armature.rigify_colors[-1].select = theme_color_set.select
armature.rigify_colors[-1].active = theme_color_set.active
return {'FINISHED'}
class DATA_OT_rigify_bone_group_remove(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_remove"
bl_label = "Rigify Remove Bone Group color set"
idx = bpy.props.IntProperty()
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
obj.data.rigify_colors.remove(self.idx)
# set layers references to 0
for l in obj.data.rigify_layers:
if l.group == self.idx + 1:
l.group = 0
elif l.group > self.idx + 1:
l.group -= 1
return {'FINISHED'}
class DATA_OT_rigify_bone_group_remove_all(bpy.types.Operator):
bl_idname = "armature.rigify_bone_group_remove_all"
bl_label = "Rigify Remove All Bone Groups"
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def execute(self, context):
obj = context.object
for i, col in enumerate(obj.data.rigify_colors):
obj.data.rigify_colors.remove(0)
# set layers references to 0
for l in obj.data.rigify_layers:
if l.group == i + 1:
l.group = 0
return {'FINISHED'}
class DATA_UL_rigify_bone_groups(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
row = layout.row(align=True)
row = row.split(percentage=0.1)
row.label(text=str(index+1))
row = row.split(percentage=0.7)
row.prop(item, "name", text='', emboss=False)
row = row.row(align=True)
icon = 'LOCKED' if item.standard_colors_lock else 'UNLOCKED'
#row.prop(item, "standard_colors_lock", text='', icon=icon)
row.prop(item, "normal", text='')
row2 = row.row(align=True)
row2.prop(item, "select", text='')
row2.prop(item, "active", text='')
#row2.enabled = not item.standard_colors_lock
row2.enabled = not bpy.context.object.data.rigify_colors_lock
class DATA_PT_rigify_bone_groups_specials(bpy.types.Menu):
bl_label = 'Rigify Bone Groups Specials'
def draw(self, context):
layout = self.layout
layout.operator('armature.rigify_bone_group_remove_all')
class DATA_PT_rigify_bone_groups(bpy.types.Panel):
bl_label = "Rigify Bone Groups"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return context.object.type == 'ARMATURE'
def draw(self, context):
obj = context.object
armature = obj.data
color_sets = obj.data.rigify_colors
idx = obj.data.rigify_colors_index
layout = self.layout
row = layout.row()
row.operator("armature.rigify_use_standard_colors", icon='FILE_REFRESH', text='')
row = row.row(align=True)
row.prop(armature.rigify_selection_colors, 'select', text='')
row.prop(armature.rigify_selection_colors, 'active', text='')
row = layout.row(align=True)
icon = 'LOCKED' if armature.rigify_colors_lock else 'UNLOCKED'
row.prop(armature, 'rigify_colors_lock', text = 'Unified select/active colors', icon=icon)
row.operator("armature.rigify_apply_selection_colors", icon='FILE_REFRESH', text='Apply')
row = layout.row()
row.template_list("DATA_UL_rigify_bone_groups", "", obj.data, "rigify_colors", obj.data, "rigify_colors_index")
col = row.column(align=True)
col.operator("armature.rigify_bone_group_add", icon='ZOOMIN', text="")
col.operator("armature.rigify_bone_group_remove", icon='ZOOMOUT', text="").idx = obj.data.rigify_colors_index
col.menu("DATA_PT_rigify_bone_groups_specials", icon='DOWNARROW_HLT', text="")
row = layout.row()
row.prop(armature, 'rigify_theme_to_add', text = 'Theme')
op = row.operator("armature.rigify_bone_group_add_theme", text="Add From Theme")
op.theme = armature.rigify_theme_to_add
row = layout.row()
row.operator("armature.rigify_add_bone_groups", text="Add Standard")
Nathan Vegdahl
committed
class BONE_PT_rigify_buttons(bpy.types.Panel):
bl_label = "Rigify Type"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "bone"
#bl_options = {'DEFAULT_OPEN'}
@classmethod
def poll(cls, context):
if not context.armature or not context.active_pose_bone:
return False
obj = context.object
if obj:
return obj.mode == 'POSE'
return False
def draw(self, context):
C = context
Campbell Barton
committed
id_store = C.window_manager
Campbell Barton
committed
collection_name = str(id_store.rigify_collection).replace(" ", "")
rig_name = str(context.active_pose_bone.rigify_type).replace(" ", "")
layout = self.layout
# Build types list
Campbell Barton
committed
for i in range(0, len(id_store.rigify_types)):
id_store.rigify_types.remove(0)
for r in rig_lists.rig_list:
rig = get_rig_type(r)
if hasattr(rig, 'IMPLEMENTATION') and rig.IMPLEMENTATION:
continue
Campbell Barton
committed
a = id_store.rigify_types.add()
a.name = r
elif r.startswith(collection_name + '.'):
Campbell Barton
committed
a = id_store.rigify_types.add()
a.name = r
elif collection_name == "None" and len(r.split('.')) == 1:
Campbell Barton
committed
a = id_store.rigify_types.add()
a.name = r
# Rig type field
row = layout.row()
Campbell Barton
committed
row.prop_search(bone, "rigify_type", id_store, "rigify_types", text="Rig type:")
# Rig type parameters / Rig type non-exist alert
if rig_name != "":
try:
rig = get_rig_type(rig_name)
rig.Rig
except (ImportError, AttributeError):
row = layout.row()
box = row.box()
box.label(text="ALERT: type \"%s\" does not exist!" % rig_name)
else:
try:
rig.parameters_ui
col = layout.column()
col.label(text="No options")
else:
col = layout.column()
col.label(text="Options:")
box = layout.box()
rig.parameters_ui(box, bone.rigify_parameters)
class VIEW3D_PT_tools_rigify_dev(bpy.types.Panel):
bl_label = "Rigify Dev Tools"
bl_category = 'Tools'
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
obj = context.active_object
if context.mode == 'EDIT_ARMATURE':
r = self.layout.row()
r.operator("armature.rigify_encode_metarig", text="Encode Metarig to Python")
r = self.layout.row()
r.operator("armature.rigify_encode_metarig_sample", text="Encode Sample to Python")
if context.mode == 'EDIT_MESH':
r = self.layout.row()
r.operator("mesh.rigify_encode_mesh_widget", text="Encode Mesh Widget to Python")
Campbell Barton
committed
#~ class INFO_MT_armature_metarig_add(bpy.types.Menu):
#~ bl_idname = "INFO_MT_armature_metarig_add"
#~ bl_label = "Meta-Rig"
Campbell Barton
committed
#~ def draw(self, context):
#~ import rigify
Campbell Barton
committed
#~ layout = self.layout
#~ layout.operator_context = 'INVOKE_REGION_WIN'
Campbell Barton
committed
#~ for submodule_type in rigify.get_submodule_types():
#~ text = bpy.path.display_name(submodule_type)
#~ layout.operator("pose.metarig_sample_add", text=text, icon='OUTLINER_OB_ARMATURE').metarig_type = submodule_type
def rigify_report_exception(operator, exception):
import traceback
import sys
import os
# find the module name where the error happened
# hint, this is the metarig type!
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
fn = traceback.extract_tb(exceptionTraceback)[-1][0]
fn = os.path.basename(fn)
fn = os.path.splitext(fn)[0]
message = []
if fn.startswith("__"):
message.append("Incorrect armature...")
else:
message.append("Incorrect armature for type '%s'" % fn)
message.append(exception.message)
message.reverse() # XXX - stupid! menu's are upside down!
Campbell Barton
committed
class LayerInit(bpy.types.Operator):
"""Initialize armature rigify layers"""
bl_idname = "pose.rigify_layer_init"
bl_label = "Add Rigify Layers"
bl_options = {'UNDO'}
def execute(self, context):
obj = context.object
arm = obj.data
for i in range(1 + len(arm.rigify_layers), 29):
arm.rigify_layers.add()
Campbell Barton
committed
return {'FINISHED'}
"""Generates a rig from the active metarig armature"""
bl_idname = "pose.rigify_generate"
bl_label = "Rigify Generate Rig"
bl_description = 'Generates a rig from the active metarig armature'
import importlib
importlib.reload(generate)
use_global_undo = context.user_preferences.edit.use_global_undo
context.user_preferences.edit.use_global_undo = False
try:
generate.generate_rig(context, context.object)
except MetarigError as rig_exception:
rigify_report_exception(self, rig_exception)
finally:
context.user_preferences.edit.use_global_undo = use_global_undo
return {'FINISHED'}
class Sample(bpy.types.Operator):
"""Create a sample metarig to be modified before generating """ \
"""the final rig"""
bl_idname = "armature.metarig_sample_add"
bl_label = "Add a sample metarig for a rig type"
metarig_type = StringProperty(
name="Type",
description="Name of the rig type to generate a sample of",
maxlen=128,
)
def execute(self, context):
if context.mode == 'EDIT_ARMATURE' and self.metarig_type != "":
use_global_undo = context.user_preferences.edit.use_global_undo
context.user_preferences.edit.use_global_undo = False
rig = get_rig_type(self.metarig_type)
create_sample = rig.create_sample
except (ImportError, AttributeError):
raise Exception("rig type '" + self.metarig_type + "' has no sample.")
else:
create_sample(context.active_object)
finally:
context.user_preferences.edit.use_global_undo = use_global_undo
bpy.ops.object.mode_set(mode='EDIT')
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
class EncodeMetarig(bpy.types.Operator):
""" Creates Python code that will generate the selected metarig.
"""
bl_idname = "armature.rigify_encode_metarig"
bl_label = "Rigify Encode Metarig"
bl_options = {'UNDO'}
@classmethod
def poll(self, context):
return context.mode == 'EDIT_ARMATURE'
def execute(self, context):
name = "metarig.py"
if name in bpy.data.texts:
text_block = bpy.data.texts[name]
text_block.clear()
else:
text_block = bpy.data.texts.new(name)
text = write_metarig(context.active_object, layers=True, func_name="create")
text_block.write(text)
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
class EncodeMetarigSample(bpy.types.Operator):
""" Creates Python code that will generate the selected metarig
as a sample.
"""
bl_idname = "armature.rigify_encode_metarig_sample"
bl_label = "Rigify Encode Metarig Sample"
bl_options = {'UNDO'}
@classmethod
def poll(self, context):
return context.mode == 'EDIT_ARMATURE'
def execute(self, context):
name = "metarig_sample.py"
if name in bpy.data.texts:
text_block = bpy.data.texts[name]
text_block.clear()
else:
text_block = bpy.data.texts.new(name)
text = write_metarig(context.active_object, layers=False, func_name="create_sample")
text_block.write(text)
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
class EncodeWidget(bpy.types.Operator):
""" Creates Python code that will generate the selected metarig.
"""
bl_idname = "mesh.rigify_encode_mesh_widget"
bl_label = "Rigify Encode Widget"
bl_options = {'UNDO'}
@classmethod
def poll(self, context):
return context.mode == 'EDIT_MESH'
def execute(self, context):
name = "widget.py"
if name in bpy.data.texts:
text_block = bpy.data.texts[name]
text_block.clear()
else:
text_block = bpy.data.texts.new(name)
text = write_widget(context.active_object)
text_block.write(text)
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
#menu_func = (lambda self, context: self.layout.menu("INFO_MT_armature_metarig_add", icon='OUTLINER_OB_ARMATURE'))
#from bl_ui import space_info # ensure the menu is loaded first
bpy.utils.register_class(DATA_OT_rigify_add_bone_groups)
bpy.utils.register_class(DATA_OT_rigify_use_standard_colors)
bpy.utils.register_class(DATA_OT_rigify_apply_selection_colors)
bpy.utils.register_class(DATA_OT_rigify_bone_group_add)
bpy.utils.register_class(DATA_OT_rigify_bone_group_add_theme)
bpy.utils.register_class(DATA_OT_rigify_bone_group_remove)
bpy.utils.register_class(DATA_OT_rigify_bone_group_remove_all)
bpy.utils.register_class(DATA_UL_rigify_bone_groups)
bpy.utils.register_class(DATA_PT_rigify_bone_groups_specials)
bpy.utils.register_class(DATA_PT_rigify_bone_groups)
Nathan Vegdahl
committed
bpy.utils.register_class(DATA_PT_rigify_layer_names)
bpy.utils.register_class(DATA_PT_rigify_buttons)
bpy.utils.register_class(BONE_PT_rigify_buttons)
bpy.utils.register_class(VIEW3D_PT_tools_rigify_dev)
Campbell Barton
committed
bpy.utils.register_class(LayerInit)
bpy.utils.register_class(Generate)
bpy.utils.register_class(Sample)
bpy.utils.register_class(EncodeMetarig)
bpy.utils.register_class(EncodeMetarigSample)
bpy.utils.register_class(EncodeWidget)
#space_info.INFO_MT_armature_add.append(ui.menu_func)
def unregister():
bpy.utils.unregister_class(DATA_OT_rigify_add_bone_groups)
bpy.utils.unregister_class(DATA_OT_rigify_use_standard_colors)
bpy.utils.unregister_class(DATA_OT_rigify_apply_selection_colors)
bpy.utils.unregister_class(DATA_OT_rigify_bone_group_add)
bpy.utils.unregister_class(DATA_OT_rigify_bone_group_add_theme)
bpy.utils.unregister_class(DATA_OT_rigify_bone_group_remove)
bpy.utils.unregister_class(DATA_OT_rigify_bone_group_remove_all)
bpy.utils.unregister_class(DATA_UL_rigify_bone_groups)
bpy.utils.unregister_class(DATA_PT_rigify_bone_groups_specials)
bpy.utils.unregister_class(DATA_PT_rigify_bone_groups)
Nathan Vegdahl
committed
bpy.utils.unregister_class(DATA_PT_rigify_layer_names)
bpy.utils.unregister_class(DATA_PT_rigify_buttons)
bpy.utils.unregister_class(BONE_PT_rigify_buttons)
bpy.utils.unregister_class(VIEW3D_PT_tools_rigify_dev)
Campbell Barton
committed
bpy.utils.unregister_class(LayerInit)
bpy.utils.unregister_class(Generate)
bpy.utils.unregister_class(Sample)
bpy.utils.unregister_class(EncodeMetarig)
bpy.utils.unregister_class(EncodeMetarigSample)