[Bf-python] Patch for Implementation of Object.getMaterials

Jonathan Thambidurai jonthambi at comcast.net
Wed Jun 18 06:18:56 CEST 2003


	Here are two small patches that implement Object.getMaterials.

--Jonathan Thambidurai
-------------- next part --------------
Index: Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.16
diff -u -r1.16 Object.c
--- Object.c	12 Jun 2003 04:51:49 -0000	1.16
+++ Object.c	18 Jun 2003 04:15:41 -0000
@@ -687,9 +687,21 @@
 
 static PyObject *Object_getMaterials (C_Object *self)
 {
-    /* TODO: Implement when the Material module is implemented. */
-    return (PythonReturnErrorObject (PyExc_NotImplementedError,
-            "getMaterials: not yet implemented"));
+  PyObject *list = PyList_New(0);
+  int i = 0;
+
+  if( !list ) 
+    {
+      return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+				    "couldn't create list" );
+    }
+
+  for( i = 0; i < self->object->totcol; i++ )
+    {
+      PyList_Append( list, Material_CreatePyObject( self->object->mat[i] ) );
+    }
+
+  return list;
 }
 
 static PyObject *Object_getMatrix (C_Object *self)
-------------- next part --------------
Index: modules.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/modules.h,v
retrieving revision 1.20
diff -u -r1.20 modules.h
--- modules.h	9 Jun 2003 04:01:48 -0000	1.20
+++ modules.h	18 Jun 2003 04:18:39 -0000
@@ -80,6 +80,7 @@
 
 /* Material */
 PyObject *      M_Material_Init (void);
+PyObject *Material_CreatePyObject (Material *mat);
 
 /* Camera Data */
 PyObject * M_Camera_Init (void);


More information about the Bf-python mailing list