From: Michel Selten Date: Sat, 3 Apr 2004 20:24:46 +0000 (+0000) Subject: Python API update. Again by Anders Nilsson. X-Git-Url: https://git.blender.org/gitweb/gitweb.cgi/blender-staging.git/commitdiff_plain/141b7673c94f406a2014dbd252e92dbb5c32f5a3 Python API update. Again by Anders Nilsson. * Addition to the Object module. obj.getActionIpos(). This method will return a dict with all ipo keys. Only works when the Object is an armature. --- diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 1674413afa7..f5514cf3350 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -89,6 +89,7 @@ struct PyMethodDef M_Object_methods[] = { static PyObject *Object_buildParts (BPy_Object *self); static PyObject *Object_clearIpo (BPy_Object *self); static PyObject *Object_clrParent (BPy_Object *self, PyObject *args); +static PyObject *Object_getActionIpos (BPy_Object *self); static PyObject *Object_getData (BPy_Object *self); static PyObject *Object_getDeltaLocation (BPy_Object *self); static PyObject *Object_getDrawMode (BPy_Object *self); @@ -136,6 +137,8 @@ static PyMethodDef BPy_Object_methods[] = { "Clears parent object. Optionally specify:\n\ mode\n\t2: Keep object transform\nfast\n\t>0: Don't update scene \ hierarchy (faster)"}, + {"getActionIpos", (PyCFunction)Object_getActionIpos, METH_NOARGS, + "() - Return a dict of (name:ipo)-keys containing each channel in the object's action"}, {"getData", (PyCFunction)Object_getData, METH_NOARGS, "Returns the datablock object containing the object's data, e.g. Mesh"}, {"getDeltaLocation", (PyCFunction)Object_getDeltaLocation, METH_NOARGS, @@ -642,6 +645,58 @@ int EXPP_add_obdata(struct Object *object) return 0; } +static PyObject *Object_getActionIpos (BPy_Object *self) +{ + Object *obj=self->object; + PyObject *dict=PyDict_New (); + + if (obj->type==OB_ARMATURE) { + + if (obj->action!=0) { + + bAction *action=obj->action; + bActionChannel *bone=(bActionChannel*)(action->chanbase.first); + + // Go through the list of bones + while (bone!=0) { + + // Does this bone have an ipo? + if (bone->ipo!=0) { + + PyObject *ipo_attr=Ipo_CreatePyObject (bone->ipo); + + if (ipo_attr) { + + // Insert dict entry using the bone name as key + if (PyDict_SetItemString (dict, bone->name, ipo_attr)!=0) { + Py_DECREF ( ipo_attr ); + Py_DECREF ( dict ); + + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Object_getActionIpos: couldn't set dict item"); + } + + Py_DECREF (ipo_attr); + + } else { + + Py_DECREF ( dict ); + + return (PythonReturnErrorObject (PyExc_RuntimeError, + "Object_getActionIpos: could not create Ipo object")); + + } + } + + bone=bone->next; + } + } + } + + return dict; +} + + static PyObject *Object_getData (BPy_Object *self) { PyObject * data_object; diff --git a/source/blender/python/api2_2x/Object.h b/source/blender/python/api2_2x/Object.h index 6502236abff..a0127d503ec 100644 --- a/source/blender/python/api2_2x/Object.h +++ b/source/blender/python/api2_2x/Object.h @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include