[Bf-python] getArmatureIpos() - third try

Anders Nilsson breakin at home.se
Sat Apr 3 15:11:17 CEST 2004


Ok this time around I think I got it all sorted out. Please let me know
if there is more errors, helps me making it right the next time around!

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/blenkernel/.sconsign
? source/blender/blenkernel/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	3 Apr 2004 13:07:46 -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,63 @@
 
   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 *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_getArmatureIpos: couldn't set dict item");
+						}
+						
+						Py_DECREF (ipo_attr);
+						
+					} else {
+						
+						Py_DECREF ( dict );
+						
+						return (PythonReturnErrorObject (PyExc_RuntimeError,
+						"Object_getArmatureIpos: could not create Ipo object"));
+
+					}
+				}
+				
+				bone=bone->next;
+			}
+		}	
+		
+		return dict;
+	}
+	
+	// Object is not an 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	3 Apr 2004 13:07:46 -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	3 Apr 2004 13:07:47 -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