[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21223] trunk/blender/source/blender/ python/api2_2x: patch [#18950] Get/set bone and type of drivers

Campbell Barton ideasman42 at gmail.com
Sun Jun 28 16:55:22 CEST 2009


Revision: 21223
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21223
Author:   campbellbarton
Date:     2009-06-28 16:55:22 +0200 (Sun, 28 Jun 2009)

Log Message:
-----------
patch [#18950] Get/set bone and type of drivers
by Alberto Torres Ruiz (dithi) 

--- quoting the patch submission
This patchs adds the properties IpoCurve.driverBone and IpoCurve.driverBone2 and modifies IpoCurve.driverChannel to
allow OB_ROT_DIFF.

It sets the driver type to pose if IpoCurve.driverBone is not empty or None. Otherwise the driver type is set to
object.

Attached is the patch (with python doc) and an example .blend.

It also fixes the confusing description of IpoCurve.driver

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

Modified: trunk/blender/source/blender/python/api2_2x/Ipocurve.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Ipocurve.c	2009-06-28 13:52:27 UTC (rev 21222)
+++ trunk/blender/source/blender/python/api2_2x/Ipocurve.c	2009-06-28 14:55:22 UTC (rev 21223)
@@ -89,10 +89,14 @@
 static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * args );
 static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self);
 static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args );
+static PyObject *IpoCurve_getDriverBone( C_IpoCurve * self);
+static PyObject *IpoCurve_getDriverBone2( C_IpoCurve * self);
 static PyObject *IpoCurve_getDriverExpression( C_IpoCurve * self);
 static PyObject *IpoCurve_getFlag( C_IpoCurve * self, void *type);
 static int IpoCurve_setFlag( C_IpoCurve * self, PyObject *value, void *type);
 
+static int IpoCurve_setDriverBone( C_IpoCurve * self, PyObject * args );
+static int IpoCurve_setDriverBone2( C_IpoCurve * self, PyObject * args );
 static int IpoCurve_setDriverExpression( C_IpoCurve * self, PyObject * args );
 static PyObject *IpoCurve_getCurval( C_IpoCurve * self, PyObject * args );
 static int IpoCurve_setCurval( C_IpoCurve * self, PyObject * key, 
@@ -159,6 +163,14 @@
 	 (getter)IpoCurve_getDriverChannel, (setter)IpoCurve_setDriverChannel,
 	 "The channel on the driver object used to drive the IpoCurve",
 	 NULL},
+	{"driverBone",
+	 (getter)IpoCurve_getDriverBone, (setter)IpoCurve_setDriverBone,
+	 "The armature bone used to drive the IpoCurve",
+	 NULL},
+	{"driverBone2",
+	 (getter)IpoCurve_getDriverBone2, (setter)IpoCurve_setDriverBone2,
+	 "The second armature bone used to drive the IpoCurve (only with ROT_DIFF channel)",
+	 NULL},
 	{"driverExpression",
 	 (getter)IpoCurve_getDriverExpression, (setter)IpoCurve_setDriverExpression,
 	 "The python expression on the driver used to drive the IpoCurve",
@@ -912,7 +924,8 @@
 	param  = (short)PyInt_AS_LONG ( args );
 	if( ( param >= OB_LOC_X && param <= OB_LOC_Z )
 			|| ( param >= OB_ROT_X && param <= OB_ROT_Z )
-			|| ( param >= OB_SIZE_X && param <= OB_SIZE_Z ) ) {
+			|| ( param >= OB_SIZE_X && param <= OB_SIZE_Z )
+			|| ( param == OB_ROT_DIFF && ipo->driver->blocktype==ID_AR ) ) {
 		ipo->driver->adrcode = (short)PyInt_AS_LONG ( args );
 		return 0;
 	}
@@ -920,6 +933,102 @@
 	return EXPP_ReturnIntError( PyExc_ValueError, "invalid int argument" );
 }
 
+static PyObject *IpoCurve_getDriverBone( C_IpoCurve * self )
+{
+	IpoCurve *ipo = self->ipocurve;
+	
+	if( ipo->driver && ipo->driver->type == IPO_DRIVER_TYPE_NORMAL && 
+			ipo->driver->ob->type==OB_ARMATURE && 
+			ipo->driver->blocktype==ID_AR )
+		return PyString_FromString( ipo->driver->name );
+
+	Py_RETURN_NONE;
+}
+
+static PyObject *IpoCurve_getDriverBone2( C_IpoCurve * self )
+{
+	IpoCurve *ipo = self->ipocurve;
+	
+	if( ipo->driver && ipo->driver->type == IPO_DRIVER_TYPE_NORMAL && 
+			ipo->driver->ob->type==OB_ARMATURE && 
+			ipo->driver->blocktype==ID_AR )
+		return PyString_FromString( ipo->driver->name+DRIVER_NAME_OFFS );
+
+	Py_RETURN_NONE;
+}
+
+static int IpoCurve_setDriverBone( C_IpoCurve * self, PyObject * arg )
+{
+	IpoCurve *ipo = self->ipocurve;
+	char *bone; /* bone name */
+	
+	if( !ipo->driver )
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+			"This IpoCurve does not have an active driver" );
+
+	if (ipo->driver->type != IPO_DRIVER_TYPE_NORMAL || 
+		  ipo->driver->ob->type!=OB_ARMATURE)
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+			"This driver is not of object type or object is not an armature" );
+	
+	if(!PyString_Check(arg) && arg!=Py_None)
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+					      "expected a string argument or None" );
+	
+	if( arg!=Py_None ){
+		bone = PyString_AsString(arg);
+		if (strlen(bone)>31)
+			return EXPP_ReturnIntError( PyExc_ValueError,
+						      "string is too long, use 31 characters or less" );
+
+		strcpy(ipo->driver->name, bone);
+		
+		if (strlen(bone)>0)
+		  ipo->driver->blocktype=ID_AR;
+		else
+		  ipo->driver->blocktype=ID_OB;
+	} else {
+		ipo->driver->name[0]=0;
+		ipo->driver->blocktype=ID_OB;
+	}
+	
+	return 0;
+}
+
+static int IpoCurve_setDriverBone2( C_IpoCurve * self, PyObject * arg )
+{
+	IpoCurve *ipo = self->ipocurve;
+	char *bone; /* bone name */
+	
+	if( !ipo->driver )
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+			"This IpoCurve does not have an active driver" );
+
+	if (ipo->driver->type != IPO_DRIVER_TYPE_NORMAL || 
+		  ipo->driver->ob->type!=OB_ARMATURE)
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+			"This driver is not of object type or object is not an armature" );
+	
+	if(!PyString_Check(arg) && arg!=Py_None)
+		return EXPP_ReturnIntError( PyExc_RuntimeError,
+					      "expected a string argument or None" );
+	
+	if( arg!=Py_None ){
+		bone = PyString_AsString(arg);
+		if (strlen(bone)>31)
+			return EXPP_ReturnIntError( PyExc_ValueError,
+						      "string is too long, use 31 characters or less" );
+
+		strcpy(ipo->driver->name+DRIVER_NAME_OFFS, bone);
+		
+	} else {
+		ipo->driver->name[DRIVER_NAME_OFFS]=0;
+	}
+	
+	return 0;
+}
+
+
 static PyObject *IpoCurve_getDriverExpression( C_IpoCurve * self )
 {
 	IpoCurve *ipo = self->ipocurve;
@@ -1010,6 +1119,7 @@
 	PyModule_AddIntConstant( submodule, "SIZE_X", OB_SIZE_X );
 	PyModule_AddIntConstant( submodule, "SIZE_Y", OB_SIZE_Y );
 	PyModule_AddIntConstant( submodule, "SIZE_Z", OB_SIZE_Z );	
+	PyModule_AddIntConstant( submodule, "ROT_DIFF", OB_ROT_DIFF );	
 
 	if( ExtendTypes )
 		PyModule_AddObject( submodule, "ExtendTypes", ExtendTypes );

Modified: trunk/blender/source/blender/python/api2_2x/doc/IpoCurve.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/IpoCurve.py	2009-06-28 13:52:27 UTC (rev 21222)
+++ trunk/blender/source/blender/python/api2_2x/doc/IpoCurve.py	2009-06-28 14:55:22 UTC (rev 21223)
@@ -50,10 +50,16 @@
   the IPO Curve Editor window.  Positive rotations are in a counter-clockwise
   direction, following the standard convention.
   
-  @ivar driver:  Status of the driver.  1= on, 0= object, 2= python expression.
+  @ivar driver:  Status of the driver.  1= object or armature/bone driver, 2= python expression, 0= no driver
   @type driver:  int
   @ivar driverObject:  Object used to drive the Ipo curve.
   @type driverObject:  Blender Object or None
+  @ivar driverBone:  Name of the armature bone used to drive the Ipo curve.
+  If empty or None, sets driver type to object, otherwise sets driver type to pose. [0 - 31 chars]
+  @type driverBone:  string or None
+  @ivar driverBone2:  Name of the second bone used to drive the Ipo curve. 
+  Only to be used with ROT_DIFF channel. [0 - 31 chars]
+  @type driverBone2:  string or None
   @ivar driverExpression:  Python expression used to drive the Ipo curve. [0 - 127 chars]
   @type driverExpression:  string
   @ivar sel:  The selection state of this curve.
@@ -61,7 +67,7 @@
   @ivar driverChannel:  Object channel used to drive the Ipo curve.
   Use module constants: IpoCurve.LOC_X, IpoCurve.LOC_Y, IpoCurve.LOC_Z,
   IpoCurve.ROT_X, IpoCurve.ROT_Y, IpoCurve.ROT_Z, IpoCurve.SIZE_X,
-  IpoCurve.SIZE_Y, IpoCurve.SIZE_Z
+  IpoCurve.SIZE_Y, IpoCurve.SIZE_Z, IpoCurve.ROT_DIFF (this last one is only for pose type drivers)
   @type driverChannel:  int 
   @ivar name: The IpoCurve data name.
   @type name: string





More information about the Bf-blender-cvs mailing list