[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10955] trunk/blender/source/blender/ python/api2_2x: == PyConstraints - BPy API Access ==
Joshua Leung
aligorith at gmail.com
Mon Jun 18 12:39:50 CEST 2007
Revision: 10955
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10955
Author: aligorith
Date: 2007-06-18 12:39:50 +0200 (Mon, 18 Jun 2007)
Log Message:
-----------
== PyConstraints - BPy API Access ==
The BPy Access to PyConstraints. I have not implemented the setter for the PyC-ID-Properties access as I'm not too sure how this should be done.
Also fixed a few typos in the py-docs for the Limit Scale constraint.
Modified Paths:
--------------
trunk/blender/source/blender/python/api2_2x/Constraint.c
trunk/blender/source/blender/python/api2_2x/doc/Constraint.py
Modified: trunk/blender/source/blender/python/api2_2x/Constraint.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Constraint.c 2007-06-18 07:41:21 UTC (rev 10954)
+++ trunk/blender/source/blender/python/api2_2x/Constraint.c 2007-06-18 10:39:50 UTC (rev 10955)
@@ -36,6 +36,7 @@
#include "DNA_effect_types.h"
#include "DNA_vec_types.h"
#include "DNA_curve_types.h"
+#include "DNA_text_types.h"
#include "BKE_main.h"
#include "BKE_global.h"
@@ -50,8 +51,10 @@
#include "blendef.h"
#include "mydevice.h"
+#include "IDProp.h"
#include "Object.h"
#include "NLA.h"
+#include "Text.h"
#include "gen_utils.h"
enum constraint_constants {
@@ -126,6 +129,9 @@
EXPP_CONSTR_LIMLOCALBONE,
EXPP_CONSTR_LIMLOCALNOPAR,
+ EXPP_CONSTR_SCRIPT,
+ EXPP_CONSTR_PROPS,
+
EXPP_CONSTR_RB_TYPE,
EXPP_CONSTR_RB_BALL,
EXPP_CONSTR_RB_HINGE,
@@ -1211,7 +1217,64 @@
}
}
+static PyObject *script_getter( BPy_Constraint * self, int type )
+{
+ bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
+ switch( type ) {
+ case EXPP_CONSTR_TARGET:
+ return Object_CreatePyObject( con->tar );
+ case EXPP_CONSTR_BONE:
+ return PyString_FromString( con->subtarget );
+ case EXPP_CONSTR_SCRIPT:
+ return Text_CreatePyObject( con->text );
+ case EXPP_CONSTR_PROPS:
+ return BPy_Wrap_IDProperty( NULL, con->prop, NULL);
+ default:
+ return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
+ }
+}
+
+static int script_setter( BPy_Constraint *self, int type, PyObject *value )
+{
+ bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
+
+ switch( type ) {
+ case EXPP_CONSTR_TARGET: {
+ Object *obj = (( BPy_Object * )value)->object;
+ if( !BPy_Object_Check( value ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected BPy object argument" );
+ con->tar = obj;
+ return 0;
+ }
+ case EXPP_CONSTR_BONE: {
+ char *name = PyString_AsString( value );
+ if( !name )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected string arg" );
+
+ BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
+
+ return 0;
+ }
+ case EXPP_CONSTR_SCRIPT: {
+ Text *text = (( BPy_Text * )value)->text;
+ if( !BPy_Object_Check( value ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected BPy text argument" );
+ con->text = text;
+ return 0;
+ }
+ case EXPP_CONSTR_PROPS:
+ return EXPP_ReturnIntError( PyExc_RuntimeError,
+ "setting ID-Properties of PyConstraints this way is not supported" );
+ default:
+ return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
+ }
+}
+
+
static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
{
bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
@@ -1380,8 +1443,9 @@
return rigidbody_getter( self, setting );
case CONSTRAINT_TYPE_CLAMPTO:
return clampto_getter( self, setting );
+ case CONSTRAINT_TYPE_PYTHON:
+ return script_getter( self, setting );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
- case CONSTRAINT_TYPE_PYTHON:
default:
return EXPP_ReturnPyObjError( PyExc_KeyError,
"unknown constraint type" );
@@ -1447,10 +1511,12 @@
case CONSTRAINT_TYPE_CLAMPTO:
result = clampto_setter( self, key_int, arg);
break;
+ case CONSTRAINT_TYPE_PYTHON:
+ result = script_setter( self, key_int, arg);
+ break;
case CONSTRAINT_TYPE_NULL:
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
- case CONSTRAINT_TYPE_PYTHON:
default:
return EXPP_ReturnIntError( PyExc_RuntimeError,
"unsupported constraint setting" );
@@ -2117,8 +2183,12 @@
PyInt_FromLong( EXPP_CONSTR_LIMLOCALBONE ) );
PyConstant_Insert( d, "LIMIT_LOCAL_NOPARENT",
PyInt_FromLong( EXPP_CONSTR_LIMLOCALNOPAR ) );
+
+ PyConstant_Insert( d, "SCRIPT",
+ PyInt_FromLong( EXPP_CONSTR_SCRIPT ) );
+ PyConstant_Insert( d, "PROPERTIES",
+ PyInt_FromLong( EXPP_CONSTR_PROPS ) );
-
PyConstant_Insert( d, "CONSTR_RB_TYPE",
PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
PyConstant_Insert( d, "CONSTR_RB_BALL",
Modified: trunk/blender/source/blender/python/api2_2x/doc/Constraint.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Constraint.py 2007-06-18 07:41:21 UTC (rev 10954)
+++ trunk/blender/source/blender/python/api2_2x/doc/Constraint.py 2007-06-18 10:39:50 UTC (rev 10955)
@@ -32,7 +32,7 @@
for comparison with L{Constraint.type}. Values are
TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
LOCKTRACK, STRETCHTO, FLOOR, LIMITLOC, LIMITROT, LIMITSIZE, CLAMPTO,
- NULL
+ PYTHON, NULL
@type Settings: readonly dictionary
@var Settings: Constant dict used for changing constraint settings.
@@ -117,12 +117,15 @@
- Used by Limit Scale (LIMITSIZE) constraint:
- LIMIT (bitfield): any combination of LIMIT_XMIN, LIMIT_XMAX,
LIMIT_YMIN, LIMIT_YMAX, LIMIT_ZMIN, LIMIT_ZMAX
- - XMIN (float): clamped to [-1000.0,1000.0]
- - XMAX (float): clamped to [-1000.0,1000.0]
- - YMIN (float): clamped to [-1000.0,1000.0]
- - YMAX (float): clamped to [-1000.0,1000.0]
- - ZMIN (float): clamped to [-1000.0,1000.0]
- - ZMAX (float): clamped to [-1000.0,1000.0]
+ - XMIN (float): clamped to [0.0001,1000.0]
+ - XMAX (float): clamped to [0.0001,1000.0]
+ - YMIN (float): clamped to [0.0001,1000.0]
+ - YMAX (float): clamped to [0.0001,1000.0]
+ - ZMIN (float): clamped to [0.0001,1000.0]
+ - ZMAX (float): clamped to [0.0001,1000.0]
+ - Used by Python Script (PYTHON) constraint:
+ - SCRIPT (Text): script to use
+ - PROPERTIES (IDProperties): ID-Properties of constraint
"""
More information about the Bf-blender-cvs
mailing list