[Bf-python] Python Object.getArmatureIpos()

Anders Nilsson breakin at home.se
Sat Apr 3 01:26:34 CEST 2004


Maybe this patch is better. It returns a dict with name:ipo-keys. Either
one works. There is one memory leak in both (mentioned in this one), I
don't know how to fix that one (it's easy but I've only coded Blender
for one day so please be patient).

This diff is created from the root of the cvs. Apply one of the patches,
not both!

Anders Nilsson (breakin)
-------------- next part --------------
? .sconsign
? blender
? config.opts
? scons-LICENSE
? scons-README
? scons-local-0.95
? scons.py
? sconsign.py
? intern/SoundSystem/.sconsign
? intern/SoundSystem/dummy/.sconsign
? intern/SoundSystem/intern/.sconsign
? intern/bmfont/.sconsign
? intern/bmfont/intern/.sconsign
? intern/bsp/extern/.sconsign
? intern/bsp/intern/.sconsign
? intern/container/.sconsign
? intern/container/intern/.sconsign
? intern/decimation/extern/.sconsign
? intern/decimation/intern/.sconsign
? intern/ghost/.sconsign
? intern/ghost/intern/.sconsign
? intern/guardedalloc/.sconsign
? intern/guardedalloc/intern/.sconsign
? intern/iksolver/extern/.sconsign
? intern/iksolver/intern/.sconsign
? intern/iksolver/intern/TNT/.sconsign
? intern/memutil/.sconsign
? intern/memutil/intern/.sconsign
? intern/moto/include/.sconsign
? intern/moto/intern/.sconsign
? intern/string/.sconsign
? intern/string/intern/.sconsign
? source/blender/avi/.sconsign
? source/blender/avi/intern/.sconsign
? source/blender/blenlib/.sconsign
? source/blender/blenlib/intern/.sconsign
? source/blender/blenloader/.sconsign
? source/blender/blenloader/intern/.sconsign
? source/blender/blenpluginapi/.sconsign
? source/blender/blenpluginapi/intern/.sconsign
? source/blender/deflate/.sconsign
? source/blender/deflate/intern/.sconsign
? source/blender/imbuf/.sconsign
? source/blender/imbuf/intern/.sconsign
? source/blender/img/.sconsign
? source/blender/img/intern/.sconsign
? source/blender/include/.sconsign
? source/blender/inflate/.sconsign
? source/blender/inflate/intern/.sconsign
? source/blender/makesdna/.sconsign
? source/blender/makesdna/intern/.sconsign
? source/blender/python/.sconsign
? source/blender/python/patch.txt
? source/blender/quicktime/.sconsign
? source/blender/radiosity/extern/include/.sconsign
? source/blender/radiosity/intern/source/.sconsign
? source/blender/readblenfile/.sconsign
? source/blender/readblenfile/intern/.sconsign
? source/blender/readstreamglue/.sconsign
? source/blender/readstreamglue/intern/.sconsign
? source/blender/render/extern/include/.sconsign
? source/blender/render/intern/include/.sconsign
? source/blender/render/intern/source/.sconsign
? source/blender/renderconverter/.sconsign
? source/blender/renderconverter/intern/.sconsign
? source/blender/src/.sconsign
? source/blender/writeblenfile/.sconsign
? source/blender/writeblenfile/intern/.sconsign
? source/blender/writestreamglue/.sconsign
? source/blender/writestreamglue/intern/.sconsign
? source/blender/yafray/.sconsign
? source/blender/yafray/intern/.sconsign
? source/creator/.sconsign
? source/kernel/gen_messaging/.sconsign
? source/kernel/gen_messaging/intern/.sconsign
? source/kernel/gen_system/.sconsign
Index: source/blender/python/api2_2x/Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.64
diff -u -r1.64 Object.c
--- source/blender/python/api2_2x/Object.c	2 Apr 2004 18:38:38 -0000	1.64
+++ source/blender/python/api2_2x/Object.c	2 Apr 2004 23:27:01 -0000
@@ -89,6 +89,7 @@
 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_getArmatureIpos (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 @@
 	"Clears parent object. Optionally specify:\n\
 mode\n\t2: Keep object transform\nfast\n\t>0: Don't update scene \
 hierarchy (faster)"},
+  {"getArmatureIpos", (PyCFunction)Object_getArmatureIpos, METH_NOARGS,
+	"() - Return a dict of (name:ipo)-keys for armature ipos"},
   {"getData", (PyCFunction)Object_getData, METH_NOARGS,
 	"Returns the datablock object containing the object's data, e.g. Mesh"},
   {"getDeltaLocation", (PyCFunction)Object_getDeltaLocation, METH_NOARGS,
@@ -641,6 +644,50 @@
 
   return 0;
 }
+
+static PyObject *Object_getArmatureIpos (BPy_Object *self)
+{
+	Object *obj=self->object;
+	
+	if (obj->type==OB_ARMATURE) {
+		
+		PyObject *dict= PyDict_New ();
+		
+		if (obj->action!=0) {
+		
+			bAction *action=obj->action;
+
+			bActionChannel *first=(bActionChannel*)(action->chanbase.first);
+			
+			while (first!=0) {
+				
+				if (first->ipo!=0) {
+					
+					PyObject *name_attr=Py_BuildValue ("s", first->name);
+					PyObject *ipo_attr=Ipo_CreatePyObject (first->ipo);
+					
+					if (name_attr && ipo_attr) {
+						if (PyDict_SetItem (dict, name_attr,ipo_attr)!=0) {
+							return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+									"Object_getArmatureIpos: couldn't set dict item");
+						}
+					} else {
+						// TODO: free the one that isn't null
+					}
+				}
+				
+				first=first->next;
+			}
+		}	
+		
+		return dict;
+	}
+	
+	// no armature
+	return (PythonReturnErrorObject (PyExc_RuntimeError,
+			"couldn't get Object.getArmatureIpos cause no armature"));
+}
+
 
 static PyObject *Object_getData (BPy_Object *self)
 {
Index: source/blender/python/api2_2x/Object.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.h,v
retrieving revision 1.20
diff -u -r1.20 Object.h
--- source/blender/python/api2_2x/Object.h	3 Mar 2004 00:45:10 -0000	1.20
+++ source/blender/python/api2_2x/Object.h	2 Apr 2004 23:27:01 -0000
@@ -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>
Index: source/blender/python/api2_2x/doc/Object.py
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/doc/Object.py,v
retrieving revision 1.14
diff -u -r1.14 Object.py
--- source/blender/python/api2_2x/doc/Object.py	2 Apr 2004 19:53:53 -0000	1.14
+++ source/blender/python/api2_2x/doc/Object.py	2 Apr 2004 23:27:01 -0000
@@ -171,6 +171,13 @@
         other value, or no value at all will update the scene hierarchy.
     """
 
+  def getArmatureIpos():
+    """
+    Returns a dict with (name:ipo)-keys for each bone if object is an armature.
+    @rtype: A dict with {name:ipo}-keys.
+    @return: A dict with {name:ipo}-keys.
+    """
+
   def getData():
     """
     Returns the Datablock object containing the object's data. For example the


More information about the Bf-python mailing list