static PyObject *Constraint_getInfluence( BPy_Constraint * self );
static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
-static PyObject *Constraint_moveUp( BPy_Constraint * self );
-static PyObject *Constraint_moveDown( BPy_Constraint * self );
static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
/*****************************************************************************/
static PyMethodDef BPy_Constraint_methods[] = {
/* name, method, flags, doc */
- {"up", ( PyCFunction ) Constraint_moveUp, METH_NOARGS,
- "Move constraint up in stack"},
- {"down", ( PyCFunction ) Constraint_moveDown, METH_NOARGS,
- "Move constraint down in stack"},
{"insertKey", ( PyCFunction ) Constraint_insertKey, METH_VARARGS,
"Insert influence keyframe for constraint"},
{NULL, NULL, 0, NULL}
return PyInt_FromLong( self->con->type );
}
-/*
- * move the constraint up in the stack
- */
-
-
-static PyObject *Constraint_moveUp( BPy_Constraint * self )
-{
- if( !self->con )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This constraint has been removed!" );
-
- const_moveUp( self->obj, self->con );
- Py_RETURN_NONE;
-}
-
-/*
- * move the constraint down in the stack
- */
-
-static PyObject *Constraint_moveDown( BPy_Constraint * self )
-{
- if( !self->con )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This constraint has been removed!" );
-
- const_moveDown( self->obj, self->con );
- Py_RETURN_NONE;
-}
-
/*
* add keyframe for influence
base on code in add_influence_key_to_constraint_func()
( intargfunc ) 0, /* sq_inplace_repeat */
};
+/*
+ * helper function to check for a valid constraint argument
+ */
+
+static bConstraint *locate_constr( BPy_ConstraintSeq *self, PyObject * args )
+{
+ BPy_Constraint *pyobj;
+ bConstraint *con;
+
+ /* check that argument is a modifier */
+ if( !PyArg_ParseTuple( args, "O!", &Constraint_Type, &pyobj ) )
+ return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected a constraint as an argument" );
+
+ /* check whether constraint has been removed */
+ if( !pyobj->con )
+ return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "This constraint has been removed!" );
+
+ /* verify the constraint is still exists in the stack */
+ if( self->pchan )
+ con = self->pchan->constraints.first;
+ else
+ con = self->obj->constraints.first;
+ while( con && con != pyobj->con )
+ con = con->next;
+
+ /* if we didn't find it, exception */
+ if( !con )
+ return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "This constraint is no longer in the object's stack" );
+
+ return con;
+}
+
+
/* create a new constraint at the end of the list */
static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *args )
BLI_addtail( &self->obj->constraints, con );
return Constraint_CreatePyObject( self->pchan, self->obj, con );
-
}
-/* remove an existing constraint */
+/* move the constraint up in the stack */
-static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, PyObject *args )
+static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, PyObject *args )
{
- BPy_Constraint *pyobj;
- Object *obj;
- bConstraint *con;
+ bConstraint *con = locate_constr( self, args );
- /* check that argument is a constraint */
- if( !PyArg_ParseTuple( args, "O!", &Constraint_Type, &pyobj ) )
- return EXPP_ReturnPyObjError( PyExc_TypeError,
- "expected a constraint as an argument" );
+ /* if we can't locate the constraint, return (exception already set) */
+ if( !con )
+ return (PyObject *)NULL;
- /*
- * check that constraintseq and constraint refer to the same object
- * (this is more for user sanity than anything else)
- */
+ const_moveUp( self->obj, con );
+ Py_RETURN_NONE;
+}
- if( self->obj != pyobj->obj )
- return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "constraint does not belong to this object" );
- obj = self->obj;
+/* move the constraint down in the stack */
- if( !pyobj->con )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This constraint has already been removed!" );
+static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, PyObject *args )
+{
+ bConstraint *con = locate_constr( self, args );
- /* verify the constraint is still exists in the stack */
- if( self->pchan )
- con = self->pchan->constraints.first;
- else
- con = obj->constraints.first;
- while( con && con != pyobj->con )
- con = con->next;
+ /* if we can't locate the constraint, return (exception already set) */
if( !con )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This constraint is no longer in the object's stack" );
+ return (PyObject *)NULL;
+
+ const_moveDown( self->obj, con );
+ Py_RETURN_NONE;
+}
+
+/* remove an existing constraint */
+
+static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, PyObject *args )
+{
+ BPy_Constraint *pyobj;
+ bConstraint *con = locate_constr( self, args );
+
+ /* if we can't locate the constraint, return (exception already set) */
+ if( !con )
+ return (PyObject *)NULL;
/* do the actual removal */
if( self->pchan )
- BLI_remlink(&(self->pchan->constraints), con);
+ BLI_remlink( &self->pchan->constraints, con );
else
- BLI_remlink(&(obj->constraints), con);
- del_constr_func (obj, con);
+ BLI_remlink( &self->obj->constraints, con);
+ del_constr_func( self->obj, con );
+ /* erase the link to the constraint */
+ pyobj = ( BPy_Constraint * )PyTuple_GET_ITEM( args, 0 );
pyobj->con = NULL;
+
Py_RETURN_NONE;
}
"(type) - add a new constraint, where type is the constraint type"},
{"remove", ( PyCFunction ) ConstraintSeq_remove, METH_VARARGS,
"(con) - remove an existing constraint, where con is a constraint from this object."},
+ {"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_VARARGS,
+ "(con) - Move constraint up in stack"},
+ {"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_VARARGS,
+ "(con) - Move constraint down in stack"},
{NULL, NULL, 0, NULL}
};
PyObject_HEAD_INIT( NULL ) /* required py macro */
0, /* ob_size */
/* For printing, in format "<module>.<name>" */
- "Blender Constraint Sequence",/* char *tp_name; */
+ "Blender.Constraints", /* char *tp_name; */
sizeof( BPy_ConstraintSeq ), /* int tp_basicsize; */
0, /* tp_itemsize; For allocation */
print bone.name,'=>',const
@type Type: readonly dictionary
-@var Type: Constant Constraint dict used by L{ConstraintSeq.append()} and
+@var Type: Constant Constraint dict used by L{Constraints.append()} and
for comparison with L{Constraint.type}. Values are
TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
LOCKTRACK, STRETCHTO, FLOOR, NULL
"""
-class ConstraintSeq:
+class Constraints:
"""
- The ConstraintSeq object
- ========================
+ The Constraints object
+ ======================
This object provides access to sequence of
L{constraints<Constraint.Constraint>} for a particular object.
They can be accessed from L{Object.constraints<Object.Object.constraints>}.
def append(type):
"""
Appends a new constraint to the end of the constraint stack.
- @type type: a constant specifying the type of constraint to create. as from L{Type}
+ @param type: a constant specifying the type of constraint to create. as from L{Type}
+ @type type: int constant
@rtype: Constraint
@return: the new Constraint
"""
- def remove(constraint):
+ def remove(con):
"""
Remove a constraint from this objects constraint sequence.
- @type constraint: a constraint from this sequence to remove.
+ @param con: a constraint from this sequence to remove.
+ @type con: Constriant
@note: Accessing attributes of the constraint after it is removed will
throw an exception.
"""
+ def moveUp(con):
+ """
+ Moves the constraint up in the object's constraint stack.
+ @param con: a constraint from this sequence to remove.
+ @type con: Constriant
+ @rtype: PyNone
+ """
+
+ def moveDown(con):
+ """
+ Moves the constraint down in the object's constraint stack.
+ @param con: a constraint from this sequence to remove.
+ @type con: Constriant
+ @rtype: PyNone
+ """
+
class Constraint:
"""
The Constraint object
=====================
This object provides access to a constraint for a particular object
- accessed from L{ConstraintSeq}.
+ accessed from L{Constraints}.
@ivar name: The name of this constraint. 29 chars max.
@type name: string
@ivar type: The type of this constraint. Read-only. The returned value
def __getitem__(key):
"""
This operator returns one of the constraint's data attributes.
- @type key: value from constraint's L{Constraint.Settings} constant
+ @param key: value from constraint's L{Constraint.Settings} constant
+ @type key: int constant
@return: the requested data
@rtype: varies
@raise KeyError: the key does not exist for the constraint
def __setitem__(key):
"""
This operator changes one of the constraint's data attributes.
- @type key: value from constraint's L{Constraint.Settings} constant
+ @param key: value from constraint's L{Constraint.Settings} constant
+ @type key: int constant
@raise KeyError: the key does not exist for the constraint
"""
- def up():
- """
- Moves the constraint up in the object's constraint stack.
- @rtype: PyNone
- """
-
- def down():
- """
- Moves the constraint down in the object's constraint stack.
- @rtype: PyNone
- """
-
def insertKey(frame):
"""
Adds an influence keyframe for the constraint Ipo.
@rtype: PyNone
- @type frame: float
@param frame: the frame number at which to insert the key.
+ @type frame: float
"""
-
-
-
-class ConstraintSeq:
- """
- The ConstraintSeq object
- ========================
- This object provides access to sequence of
- L{constraints<Constraint.Constraint>} for a particular object.
- They can be accessed from L{Object.constraints<Object.Object.constraints>}.
- or L{PoseBone.constraints<Pose.PoseBone.constraints>}.
- """
-
- def __getitem__(index):
- """
- This operator returns one of the constraints in the stack.
- @type index: int
- @return: an Constraint object
- @rtype: Constraint
- @raise KeyError: index was out of range
- """
-
- def __len__():
- """
- Returns the number of constraints in the constraint stack.
- @return: number of Constraints
- @rtype: int
- """
-
- def append(type):
- """
- Appends a new constraint to the end of the constraint stack.
- @type type: a constant specifying the type of constraint to create. as from L{Type}
- @rtype: Constraint
- @return: the new Constraint
- """
-
- def remove(constraint):
- """
- Remove a constraint from this objects constraint sequence.
- @type constraint: a constraint from this sequence to remove.
- @note: Accessing attributes of the constraint after removing will
- throw an exception.
- """
-