[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20392] trunk/blender/source/blender/ python/api2_2x/Constraint.c: [#18731] trouble with the python api in assigning script constraint's target.

Campbell Barton ideasman42 at gmail.com
Mon May 25 03:45:36 CEST 2009


Revision: 20392
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20392
Author:   campbellbarton
Date:     2009-05-25 03:45:35 +0200 (Mon, 25 May 2009)

Log Message:
-----------
[#18731] trouble with the python api in assigning script constraint's target.
- Setting the constraint script from python didnt update the target count
- Setting objects didnt work at all, since it checked the input sequence for being an BPy_Object type (rather then an item in the sequence)

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Constraint.c

Modified: trunk/blender/source/blender/python/api2_2x/Constraint.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Constraint.c	2009-05-25 01:00:17 UTC (rev 20391)
+++ trunk/blender/source/blender/python/api2_2x/Constraint.c	2009-05-25 01:45:35 UTC (rev 20392)
@@ -52,6 +52,7 @@
 #include "blendef.h"
 #include "mydevice.h"
 
+#include "../BPY_extern.h" // BPY_pyconstraint_update
 #include "IDProp.h"
 #include "Object.h"
 #include "NLA.h"
@@ -1498,6 +1499,11 @@
 			bConstraintTarget *ct;
 			int ok= 0;
 			
+			if (PySequence_Check(value) == 0 || PyString_Check(value)) {
+				PyErr_SetString(PyExc_TypeError, "expected a sequence of strings or blender");
+				return -1;
+			}
+			
 			if (cti) {
 				/* change space of targets */
 				if (cti->get_constraint_targets) {
@@ -1506,13 +1512,12 @@
 					
 					/* get targets, and extract values from the given list */
 					num_tars= cti->get_constraint_targets(self->con, &targets);
+					if ((PySequence_Size(value) != num_tars)) {
+						PyErr_Format(PyExc_TypeError, "expected sequence of strings or blender objects - %d length", num_tars);
+						return -1;
+					}
+					
 					if (num_tars) {
-						if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) {
-							char errorstr[64];
-							sprintf(errorstr, "expected sequence of %d integer(s)", num_tars);
-							return EXPP_ReturnIntError(PyExc_TypeError, errorstr);
-						}
-						
 						for (ct=targets.first; ct; ct=ct->next, i++) {
 							PyObject *val= PySequence_ITEM(value, i);
 								
@@ -1530,10 +1535,11 @@
 								
 								BLI_strncpy(ct->subtarget, name, sizeof(ct->subtarget));
 							}
-							else {
+							else /* if EXPP_CONSTR_TARGET */ {
+								
 								Object *obj = (( BPy_Object * )val)->object;
 								
-								if ( !BPy_Object_Check(value) ) {
+								if ( !BPy_Object_Check(val) ) {
 									// hrm... should we break here instead?
 									ok = EXPP_ReturnIntError(PyExc_TypeError, 
 												"expected BPy object argument as member of list");
@@ -1564,6 +1570,7 @@
 			return EXPP_ReturnIntError( PyExc_TypeError, 
 					"expected BPy text argument" );
 		con->text = text;
+		BPY_pyconstraint_update(self->obj, self->con);
 		return 0;
 		}
 	case EXPP_CONSTR_PROPS:





More information about the Bf-blender-cvs mailing list