== 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.
This commit is contained in:
Joshua Leung 2007-06-18 10:39:50 +00:00
parent 01e8789f3f
commit 25ec0533a9
2 changed files with 83 additions and 10 deletions

@ -36,6 +36,7 @@
#include "DNA_effect_types.h" #include "DNA_effect_types.h"
#include "DNA_vec_types.h" #include "DNA_vec_types.h"
#include "DNA_curve_types.h" #include "DNA_curve_types.h"
#include "DNA_text_types.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_global.h" #include "BKE_global.h"
@ -50,8 +51,10 @@
#include "blendef.h" #include "blendef.h"
#include "mydevice.h" #include "mydevice.h"
#include "IDProp.h"
#include "Object.h" #include "Object.h"
#include "NLA.h" #include "NLA.h"
#include "Text.h"
#include "gen_utils.h" #include "gen_utils.h"
enum constraint_constants { enum constraint_constants {
@ -126,6 +129,9 @@ enum constraint_constants {
EXPP_CONSTR_LIMLOCALBONE, EXPP_CONSTR_LIMLOCALBONE,
EXPP_CONSTR_LIMLOCALNOPAR, EXPP_CONSTR_LIMLOCALNOPAR,
EXPP_CONSTR_SCRIPT,
EXPP_CONSTR_PROPS,
EXPP_CONSTR_RB_TYPE, EXPP_CONSTR_RB_TYPE,
EXPP_CONSTR_RB_BALL, EXPP_CONSTR_RB_BALL,
EXPP_CONSTR_RB_HINGE, EXPP_CONSTR_RB_HINGE,
@ -1211,6 +1217,63 @@ static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
} }
} }
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) static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
{ {
@ -1380,8 +1443,9 @@ static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
return rigidbody_getter( self, setting ); return rigidbody_getter( self, setting );
case CONSTRAINT_TYPE_CLAMPTO: case CONSTRAINT_TYPE_CLAMPTO:
return clampto_getter( self, setting ); return clampto_getter( self, setting );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
case CONSTRAINT_TYPE_PYTHON: case CONSTRAINT_TYPE_PYTHON:
return script_getter( self, setting );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
default: default:
return EXPP_ReturnPyObjError( PyExc_KeyError, return EXPP_ReturnPyObjError( PyExc_KeyError,
"unknown constraint type" ); "unknown constraint type" );
@ -1447,10 +1511,12 @@ static int Constraint_setData( BPy_Constraint * self, PyObject * key,
case CONSTRAINT_TYPE_CLAMPTO: case CONSTRAINT_TYPE_CLAMPTO:
result = clampto_setter( self, key_int, arg); result = clampto_setter( self, key_int, arg);
break; break;
case CONSTRAINT_TYPE_PYTHON:
result = script_setter( self, key_int, arg);
break;
case CONSTRAINT_TYPE_NULL: case CONSTRAINT_TYPE_NULL:
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" ); return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */ case CONSTRAINT_TYPE_CHILDOF: /* Unimplemented */
case CONSTRAINT_TYPE_PYTHON:
default: default:
return EXPP_ReturnIntError( PyExc_RuntimeError, return EXPP_ReturnIntError( PyExc_RuntimeError,
"unsupported constraint setting" ); "unsupported constraint setting" );
@ -2118,6 +2184,10 @@ static PyObject *M_Constraint_SettingsDict( void )
PyConstant_Insert( d, "LIMIT_LOCAL_NOPARENT", PyConstant_Insert( d, "LIMIT_LOCAL_NOPARENT",
PyInt_FromLong( EXPP_CONSTR_LIMLOCALNOPAR ) ); 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", PyConstant_Insert( d, "CONSTR_RB_TYPE",
PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) ); PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );

@ -32,7 +32,7 @@ Or to print all the constraints attached to each bone in a pose::
for comparison with L{Constraint.type}. Values are for comparison with L{Constraint.type}. Values are
TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION, TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
LOCKTRACK, STRETCHTO, FLOOR, LIMITLOC, LIMITROT, LIMITSIZE, CLAMPTO, LOCKTRACK, STRETCHTO, FLOOR, LIMITLOC, LIMITROT, LIMITSIZE, CLAMPTO,
NULL PYTHON, NULL
@type Settings: readonly dictionary @type Settings: readonly dictionary
@var Settings: Constant dict used for changing constraint settings. @var Settings: Constant dict used for changing constraint settings.
@ -117,12 +117,15 @@ Or to print all the constraints attached to each bone in a pose::
- Used by Limit Scale (LIMITSIZE) constraint: - Used by Limit Scale (LIMITSIZE) constraint:
- LIMIT (bitfield): any combination of LIMIT_XMIN, LIMIT_XMAX, - LIMIT (bitfield): any combination of LIMIT_XMIN, LIMIT_XMAX,
LIMIT_YMIN, LIMIT_YMAX, LIMIT_ZMIN, LIMIT_ZMAX LIMIT_YMIN, LIMIT_YMAX, LIMIT_ZMIN, LIMIT_ZMAX
- XMIN (float): clamped to [-1000.0,1000.0] - XMIN (float): clamped to [0.0001,1000.0]
- XMAX (float): clamped to [-1000.0,1000.0] - XMAX (float): clamped to [0.0001,1000.0]
- YMIN (float): clamped to [-1000.0,1000.0] - YMIN (float): clamped to [0.0001,1000.0]
- YMAX (float): clamped to [-1000.0,1000.0] - YMAX (float): clamped to [0.0001,1000.0]
- ZMIN (float): clamped to [-1000.0,1000.0] - ZMIN (float): clamped to [0.0001,1000.0]
- ZMAX (float): clamped to [-1000.0,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
""" """