Constraints Py-Api:
Fixed up Py-API access to PyConstraints. Also updated docs to reflect these changes.
This commit is contained in:
@@ -1391,11 +1391,40 @@ static PyObject *script_getter( BPy_Constraint * self, int type )
|
|||||||
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
|
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
|
||||||
|
|
||||||
switch( type ) {
|
switch( type ) {
|
||||||
// FIXME!!!
|
case EXPP_CONSTR_TARGET:
|
||||||
//case EXPP_CONSTR_TARGET:
|
case EXPP_CONSTR_BONE:
|
||||||
// return Object_CreatePyObject( con->tar );
|
{
|
||||||
//case EXPP_CONSTR_BONE:
|
bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON);
|
||||||
// return PyString_FromString( con->subtarget );
|
bConstraintTarget *ct;
|
||||||
|
PyObject *tlist=NULL, *val;
|
||||||
|
|
||||||
|
if (cti) {
|
||||||
|
/* change space of targets */
|
||||||
|
if (cti->get_constraint_targets) {
|
||||||
|
ListBase targets = {NULL, NULL};
|
||||||
|
int num_tars=0, i=0;
|
||||||
|
|
||||||
|
/* get targets, and create py-list for use temporarily */
|
||||||
|
num_tars= cti->get_constraint_targets(self->con, &targets);
|
||||||
|
if (num_tars) {
|
||||||
|
tlist= PyList_New(num_tars);
|
||||||
|
|
||||||
|
for (ct=targets.first; ct; ct=ct->next, i++) {
|
||||||
|
if (type == EXPP_CONSTR_BONE)
|
||||||
|
val= PyString_FromString(ct->subtarget);
|
||||||
|
else
|
||||||
|
val= Object_CreatePyObject(ct->tar);
|
||||||
|
PyList_SET_ITEM(tlist, i, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cti->flush_constraint_targets)
|
||||||
|
cti->flush_constraint_targets(self->con, &targets, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tlist;
|
||||||
|
}
|
||||||
case EXPP_CONSTR_SCRIPT:
|
case EXPP_CONSTR_SCRIPT:
|
||||||
return Text_CreatePyObject( con->text );
|
return Text_CreatePyObject( con->text );
|
||||||
case EXPP_CONSTR_PROPS:
|
case EXPP_CONSTR_PROPS:
|
||||||
@@ -1410,25 +1439,73 @@ static int script_setter( BPy_Constraint *self, int type, PyObject *value )
|
|||||||
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
|
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
|
||||||
|
|
||||||
switch( type ) {
|
switch( type ) {
|
||||||
// FIXME!!!
|
case EXPP_CONSTR_TARGET:
|
||||||
//case EXPP_CONSTR_TARGET: {
|
case EXPP_CONSTR_BONE:
|
||||||
// Object *obj = (( BPy_Object * )value)->object;
|
{
|
||||||
// if( !BPy_Object_Check( value ) )
|
bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON);
|
||||||
// return EXPP_ReturnIntError( PyExc_TypeError,
|
bConstraintTarget *ct;
|
||||||
// "expected BPy object argument" );
|
int ok= 0;
|
||||||
// con->tar = obj;
|
|
||||||
// return 0;
|
if (cti) {
|
||||||
// }
|
/* change space of targets */
|
||||||
//case EXPP_CONSTR_BONE: {
|
if (cti->get_constraint_targets) {
|
||||||
// char *name = PyString_AsString( value );
|
ListBase targets = {NULL, NULL};
|
||||||
// if( !name )
|
int num_tars=0, i=0;
|
||||||
// return EXPP_ReturnIntError( PyExc_TypeError,
|
|
||||||
// "expected string arg" );
|
/* get targets, and extract values from the given list */
|
||||||
//
|
num_tars= cti->get_constraint_targets(self->con, &targets);
|
||||||
// BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
|
if (num_tars) {
|
||||||
//
|
if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) {
|
||||||
// return 0;
|
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);
|
||||||
|
|
||||||
|
if (type == EXPP_CONSTR_BONE) {
|
||||||
|
char *name = PyString_AsString(val);
|
||||||
|
|
||||||
|
if (name == NULL) {
|
||||||
|
// hrm... should we break here instead?
|
||||||
|
ok = EXPP_ReturnIntError(PyExc_TypeError,
|
||||||
|
"expected string arg as member of list");
|
||||||
|
Py_DECREF(val);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
BLI_strncpy(ct->subtarget, name, sizeof(ct->subtarget));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Object *obj = (( BPy_Object * )val)->object;
|
||||||
|
|
||||||
|
if ( !BPy_Object_Check(value) ) {
|
||||||
|
// hrm... should we break here instead?
|
||||||
|
ok = EXPP_ReturnIntError(PyExc_TypeError,
|
||||||
|
"expected BPy object argument as member of list");
|
||||||
|
Py_DECREF(val);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ct->tar = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_DECREF(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* only flush changes to real constraints if all were successful */
|
||||||
|
if ((cti->flush_constraint_targets) && (ok == 0))
|
||||||
|
cti->flush_constraint_targets(self->con, &targets, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case EXPP_CONSTR_SCRIPT: {
|
case EXPP_CONSTR_SCRIPT: {
|
||||||
Text *text = (( BPy_Text * )value)->text;
|
Text *text = (( BPy_Text * )value)->text;
|
||||||
if( !BPy_Object_Check( value ) )
|
if( !BPy_Object_Check( value ) )
|
||||||
|
|||||||
@@ -36,12 +36,16 @@ Or to print all the constraints attached to each bone in a pose::
|
|||||||
|
|
||||||
@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.
|
||||||
- Used for all constraints
|
- Used for all single-target constraints
|
||||||
- TARGET (Object) (Note: not used by Limit Location (LIMITLOC),
|
(TRACKTO, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION, LOCKTRACK, STRETCHTO, FLOOR, CLAMPTO, CHILDOF, TRANSFORM)
|
||||||
Limit Rotation (LIMITROT), Limit Scale (LIMITSIZE))
|
- TARGET (Object): target object
|
||||||
- BONE (string): name of Bone sub-target (for armature targets) (Note: not
|
- BONE (string): name of Bone sub-target (for Armature targets), or name of Vertex Group sub-target
|
||||||
used by Stretch To (STRETCHTO), Limit Location (LIMITLOC), Limit Rotation
|
(for Geometry targets)
|
||||||
(LIMITROT), Limit Scale (LIMITSIZE), Follow Path (FOLLOWPATH), Clamp To (CLAMPTO))
|
- Used for all multiple-target constraints
|
||||||
|
(PYTHON)
|
||||||
|
- TARGET (list of Objects): list of target objects, with one list slot = one target slot
|
||||||
|
- BONE (list of strings): list of names of Bone sub-target (for Armature targets) or name of Vertex Group
|
||||||
|
sub-targets (for Geometry targets)
|
||||||
- Used by some constraints:
|
- Used by some constraints:
|
||||||
- OWNERSPACE (int): for TRACKTO, COPYLOC, COPYROT, COPYSIZE, LIMITLOC, LIMITROT, LIMITSIZE, PYTHON, TRANSFORM
|
- OWNERSPACE (int): for TRACKTO, COPYLOC, COPYROT, COPYSIZE, LIMITLOC, LIMITROT, LIMITSIZE, PYTHON, TRANSFORM
|
||||||
If the owner is an object, values are SPACE_WORLD, SPACE_LOCAL
|
If the owner is an object, values are SPACE_WORLD, SPACE_LOCAL
|
||||||
|
|||||||
Reference in New Issue
Block a user