[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25076] trunk/blender: - bpy.data. add_armature()

Campbell Barton ideasman42 at gmail.com
Wed Dec 2 16:37:07 CET 2009


Revision: 25076
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25076
Author:   campbellbarton
Date:     2009-12-02 16:37:07 +0100 (Wed, 02 Dec 2009)

Log Message:
-----------
- bpy.data.add_armature()
- rigify testnig function, creates all example metarigs, processes and generates graphs for before and after.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/rigify/__init__.py
    trunk/blender/source/blender/makesrna/intern/rna_main_api.c

Modified: trunk/blender/release/scripts/modules/rigify/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-02 15:02:29 UTC (rev 25075)
+++ trunk/blender/release/scripts/modules/rigify/__init__.py	2009-12-02 15:37:07 UTC (rev 25076)
@@ -226,10 +226,13 @@
     # context.scene.update()
     
     # Only for demo'ing
-    ob.restrict_view = True
+    
+    # ob.restrict_view = True
     ob_new.data.draw_axes = False
     
     context.user_preferences.edit.global_undo = global_undo
+    
+    return ob_new
 
 
 def write_meta_rig(obj, func_name="metarig_template"):
@@ -291,5 +294,67 @@
     return "\n".join(code)
 
 
+def generate_test(context):
+    import os
+    new_objects = []
+    
+    scene = context.scene
+    def create_empty_armature(name):
+        ob_new = bpy.data.add_object('ARMATURE', name)
+        armature = bpy.data.add_armature(name)
+        ob_new.data = armature
+        scene.objects.link(ob_new)
+        scene.objects.active = ob_new
+
+    print(os.path.basename(__file__))
+    files = os.listdir(os.path.dirname(__file__))
+    for f in files:
+        if f.startswith("_"):
+            continue
+
+        if not f.endswith(".py"):
+            continue
+
+        module_name = f[:-3]
+        submodule = __import__(name="%s.%s" % (__package__, module_name), fromlist=[module_name])
+
+        metarig_template = getattr(submodule, "metarig_template", None)
+
+        if metarig_template:
+            create_empty_armature("meta_" + module_name) # sets active
+            metarig_template()
+            ob = context.object
+            ob_new = generate_rig(context, ob)
+            
+            new_objects.append((ob, ob_new))
+        else:
+            print("note: rig type '%s' has no metarig_template(), can't test this", module_name)
+    
+    return new_objects
+
+def generate_test_all(context):
+    import rigify
+    import graphviz_export
+    import os
+    reload(rigify)
+    reload(graphviz_export)
+    
+    new_objects = rigify.generate_test(context)
+    
+    base_name = os.path.splitext(bpy.data.filename)[0]
+    for obj, obj_new in new_objects:
+        
+        for ob in (obj, obj_new):
+            fn = base_name + "-" + bpy.utils.clean_name(ob.name)
+            
+            path_dot = fn + ".dot"
+            path_png = fn + ".png"
+            saved = graphviz_export.graph_armature(ob, path_dot, CONSTRAINTS=True, DRIVERS=True)
+
+            if saved:
+                os.system("dot -Tpng %s > %s; eog %s" % (path_dot, path_png, path_png))
+    
+
 if __name__ == "__main__":
     generate_rig(bpy.context, bpy.context.object)
+

Modified: trunk/blender/source/blender/makesrna/intern/rna_main_api.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2009-12-02 15:02:29 UTC (rev 25075)
+++ trunk/blender/source/blender/makesrna/intern/rna_main_api.c	2009-12-02 15:37:07 UTC (rev 25076)
@@ -33,21 +33,22 @@
 #include "RNA_types.h"
 #include "RNA_enum_types.h"
 
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_mesh_types.h"
-
 #ifdef RNA_RUNTIME
 
 #include "BKE_main.h"
 #include "BKE_mesh.h"
+#include "BKE_armature.h"
 #include "BKE_library.h"
 #include "BKE_object.h"
 #include "BKE_material.h"
 #include "BKE_image.h"
 #include "BKE_texture.h"
 
+#include "DNA_armature_types.h"
 #include "DNA_lamp_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
 
 static Mesh *rna_Main_add_mesh(Main *main, char *name)
 {
@@ -66,6 +67,23 @@
 	/* XXX python now has invalid pointer? */
 }
 
+static void rna_Main_remove_armature(Main *main, ReportList *reports, bArmature *arm)
+{
+	if(arm->id.us == 0)
+		free_libblock(&main->armature, arm);
+	else
+		BKE_report(reports, RPT_ERROR, "Armature must have zero users to be removed.");
+
+	/* XXX python now has invalid pointer? */
+}
+
+static bArmature *rna_Main_add_armature(Main *main, char *name)
+{
+	bArmature *arm= add_armature(name);
+	arm->id.us--;
+	return arm;
+}
+
 static Lamp *rna_Main_add_lamp(Main *main, char *name)
 {
 	Lamp *la= add_lamp(name);
@@ -164,6 +182,19 @@
 	parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove.");
 	RNA_def_property_flag(parm, PROP_REQUIRED);
 
+	func= RNA_def_function(srna, "add_armature", "rna_Main_add_armature");
+	RNA_def_function_ui_description(func, "Add a new armature.");
+	parm= RNA_def_string(func, "name", "Armature", 0, "", "New name for the datablock.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+	parm= RNA_def_pointer(func, "armature", "Armature", "", "New armature.");
+	RNA_def_function_return(func, parm);
+
+	func= RNA_def_function(srna, "remove_armature", "rna_Main_remove_armature");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	RNA_def_function_ui_description(func, "Remove an armature if it has zero users.");
+	parm= RNA_def_pointer(func, "armature", "Armature", "", "Armature to remove.");
+	RNA_def_property_flag(parm, PROP_REQUIRED);
+
 	func= RNA_def_function(srna, "add_lamp", "rna_Main_add_lamp");
 	RNA_def_function_ui_description(func, "Add a new lamp.");
 	parm= RNA_def_string(func, "name", "Lamp", 0, "", "New name for the datablock.");





More information about the Bf-blender-cvs mailing list