[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15016] trunk/blender/source/blender/ python/api2_2x: [#10223] a new object function to add vertex group from an armature

Martin Poirier theeth at yahoo.com
Tue May 27 22:02:38 CEST 2008


Revision: 15016
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15016
Author:   theeth
Date:     2008-05-27 22:02:38 +0200 (Tue, 27 May 2008)

Log Message:
-----------
[#10223] a new object function to add vertex group from an armature

Patch from Jean-Michel Soler (with slight modifs)

Small BPy feature to help script writers deal with armatures and vertex groups (calls the bone heat method to create and assign groups)

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Object.c
    trunk/blender/source/blender/python/api2_2x/doc/Object.py

Modified: trunk/blender/source/blender/python/api2_2x/Object.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Object.c	2008-05-27 18:40:33 UTC (rev 15015)
+++ trunk/blender/source/blender/python/api2_2x/Object.c	2008-05-27 20:02:38 UTC (rev 15016)
@@ -341,6 +341,7 @@
 
 static PyObject *Object_getParticleSys( BPy_Object * self );
 /* fixme Object_newParticleSys( self, default-partsys-name ) */
+static PyObject *Object_addVertexGroupsFromArmature( BPy_Object * self, PyObject * args);
 static PyObject *Object_newParticleSys( BPy_Object * self );
 static PyObject *Object_buildParts( BPy_Object * self );
 static PyObject *Object_clearIpo( BPy_Object * self );
@@ -475,6 +476,8 @@
 	 "Return a list of particle systems"},
  	{"newParticleSystem", ( PyCFunction ) Object_newParticleSys, METH_NOARGS,
 	 "Create and link a new particle system"},
+	{"addVertexGroupsFromArmature" , ( PyCFunction ) Object_addVertexGroupsFromArmature, METH_VARARGS,
+	 "Add vertex groups from armature using the bone heat method"},
 	{"buildParts", ( PyCFunction ) Object_buildParts, METH_NOARGS,
 	 "Recalcs particle system (if any), (depricated, will always return an empty list in version 2.46)"},
 	{"getIpo", ( PyCFunction ) Object_getIpo, METH_NOARGS,
@@ -1109,6 +1112,42 @@
 	return ParticleSys_CreatePyObject(rpsys,ob);
 }
 
+/*****************************************************************************/
+/* attribute:           addVertexGroupsFromArmature                          */
+/* Description:         evaluate and add vertex groups to the current object */
+/*                      for each bone of the selected armature               */   
+/* Data:                self Object, Bpy armature                            */
+/* Return:              nothing                                              */
+/*****************************************************************************/
+static PyObject *Object_addVertexGroupsFromArmature( BPy_Object * self, PyObject * args)
+{
+	
+	Object *ob = self->object;
+	BPy_Object *arm;
+
+	if( ob->type != OB_MESH )
+		return EXPP_ReturnPyObjError( PyExc_TypeError,
+				"Only useable on Mesh type Objects" );
+	
+	if( G.obedit != NULL)
+		return EXPP_ReturnPyObjError( PyExc_TypeError,
+				"Not useable when inside edit mode" );
+	
+	/* Check if the arguments passed to makeParent are valid. */
+	if( !PyArg_ParseTuple( args, "O!",&Object_Type, &arm ) )
+		return EXPP_ReturnPyObjError( PyExc_TypeError,
+				"An armature object is expected." );
+	
+	if( arm->object->type != OB_ARMATURE ) 
+		return EXPP_ReturnPyObjError( PyExc_TypeError,
+				"An armature object is expected." );
+			
+	add_verts_to_dgroups(ob, arm->object, 1, 0);
+	ob->recalc |= OB_RECALC_OB;  
+	
+	Py_RETURN_NONE;
+}
+
 static PyObject *Object_buildParts( BPy_Object * self )
 {
 	/* This is now handles by modifiers */

Modified: trunk/blender/source/blender/python/api2_2x/doc/Object.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Object.py	2008-05-27 18:40:33 UTC (rev 15015)
+++ trunk/blender/source/blender/python/api2_2x/doc/Object.py	2008-05-27 20:02:38 UTC (rev 15016)
@@ -651,6 +651,13 @@
 		Link a new particle system (see Blender.Particle).
 		"""
 		
+	def addVertexGroupsFromArmature(object):
+		"""
+		Add vertex groups from armature using the bone heat method
+		This method can be only used with an Object of the type Mesh when NOT in edit mode.
+		@type object: a bpy armature
+		"""
+
 	def buildParts():
 		"""
 		Recomputes the particle system. This method only applies to an Object of





More information about the Bf-blender-cvs mailing list