Python API update. Again by Anders Nilsson.
authorMichel Selten <michel@mselten.demon.nl>
Sat, 3 Apr 2004 20:24:46 +0000 (20:24 +0000)
committerMichel Selten <michel@mselten.demon.nl>
Sat, 3 Apr 2004 20:24:46 +0000 (20:24 +0000)
* 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.

source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/Object.h

index 1674413afa7af061810e95dff8c27b156d0132dd..f5514cf3350f6d3856c4dd243b999cafa4a386ba 100644 (file)
@@ -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;
index 6502236abffc318a2a8795a99f4df69c7df526f5..a0127d503ec98ea401e2fbbaf20b685427375d55 100644 (file)
@@ -49,6 +49,7 @@
 #include <BLI_arithb.h>
 #include <BLI_blenlib.h>
 #include <DNA_armature_types.h>
+#include <DNA_action_types.h>
 #include <DNA_ID.h>
 #include <DNA_ika_types.h>
 #include <DNA_listBase.h>