[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4286] trunk/py/scripts/addons/rigify/ ui.py: Rigify: added a developers tools panel.

Nathan Vegdahl cessen at cessen.com
Sat Feb 16 22:12:10 CET 2013


Revision: 4286
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4286
Author:   cessen
Date:     2013-02-16 21:12:09 +0000 (Sat, 16 Feb 2013)
Log Message:
-----------
Rigify: added a developers tools panel.

Contains buttons for operators that are useful when developing for
Rigify.  For now, it's buttons that generate python code for recreating
selected armatures.

Modified Paths:
--------------
    trunk/py/scripts/addons/rigify/ui.py

Modified: trunk/py/scripts/addons/rigify/ui.py
===================================================================
--- trunk/py/scripts/addons/rigify/ui.py	2013-02-16 19:35:26 UTC (rev 4285)
+++ trunk/py/scripts/addons/rigify/ui.py	2013-02-16 21:12:09 UTC (rev 4286)
@@ -21,7 +21,7 @@
 import bpy
 from bpy.props import StringProperty
 
-from .utils import get_rig_type, MetarigError
+from .utils import get_rig_type, write_metarig, MetarigError
 from . import rig_lists
 from . import generate
 
@@ -196,6 +196,22 @@
                     rig.parameters_ui(box, bone.rigify_parameters)
 
 
+class VIEW3D_PT_tools_rigify_dev(bpy.types.Panel):
+    bl_label = "Rigify Dev Tools"
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'TOOLS'
+
+    @classmethod
+    def poll(cls, context):
+        return obj.mode == 'EDIT_ARMATURE'
+
+    def draw(self, context):
+        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")
+
+
 #~ class INFO_MT_armature_metarig_add(bpy.types.Menu):
     #~ bl_idname = "INFO_MT_armature_metarig_add"
     #~ bl_label = "Meta-Rig"
@@ -303,6 +319,61 @@
         return {'FINISHED'}
 
 
+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'}
+
+
 #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
@@ -311,9 +382,12 @@
     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)
     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)
 
     #space_info.INFO_MT_armature_add.append(ui.menu_func)
 
@@ -322,6 +396,9 @@
     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)
     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)



More information about the Bf-extensions-cvs mailing list