BPython API
authorCampbell Barton <ideasman42@gmail.com>
Fri, 23 Feb 2007 14:51:20 +0000 (14:51 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 23 Feb 2007 14:51:20 +0000 (14:51 +0000)
* Added data.lib attributes to almost all data types, (except for Text3d and NLA)
  This is None or the path of the library as a string.
* Main was giving a warning, Include Curve.h rather then CurNurb.h
* Added Library.LinkedLibs(), returns a list of externaly linked libs.

20 files changed:
source/blender/python/api2_2x/Armature.c
source/blender/python/api2_2x/Camera.c
source/blender/python/api2_2x/Curve.c
source/blender/python/api2_2x/Font.c
source/blender/python/api2_2x/Group.c
source/blender/python/api2_2x/Image.c
source/blender/python/api2_2x/Ipo.c
source/blender/python/api2_2x/Lamp.c
source/blender/python/api2_2x/Lattice.c
source/blender/python/api2_2x/Library.c
source/blender/python/api2_2x/Main.c
source/blender/python/api2_2x/Material.c
source/blender/python/api2_2x/Mesh.c
source/blender/python/api2_2x/Metaball.c
source/blender/python/api2_2x/Object.c
source/blender/python/api2_2x/Scene.c
source/blender/python/api2_2x/Sound.c
source/blender/python/api2_2x/World.c
source/blender/python/api2_2x/gen_utils.c
source/blender/python/api2_2x/gen_utils.h

index 8c3ed7506c9c6565e878d0d00e912f9604fc3b9c..f91c31b25db31c7899ca044b56b7e8ca447dbaa4 100644 (file)
@@ -960,6 +960,14 @@ AttributeError:
        return EXPP_intError(PyExc_AttributeError, "%s%s", 
                sArmatureBadArgs, "Expects string");
 }
+
+//------------------------Armature.name (getter)
+//Gets the name of the armature
+static PyObject *Armature_getLib(BPy_Armature *self, void *closure)
+{
+       return EXPP_GetIdLib((ID *)self->armature);
+}
+
 //------------------------Armature.bones (getter)
 //Gets the name of the armature
 static PyObject *Armature_getBoneDict(BPy_Armature *self, void *closure)
@@ -998,6 +1006,8 @@ static PyMethodDef BPy_Armature_methods[] = {
 static PyGetSetDef BPy_Armature_getset[] = {
        {"name", (getter)Armature_getName, (setter)Armature_setName, 
                "The armature's name", NULL},
+       {"lib", (getter)Armature_getLib, (setter)NULL, 
+               "The armature's library or None", NULL},
        {"bones", (getter)Armature_getBoneDict, (setter)Armature_setBoneDict, 
                "The armature's Bone dictionary", NULL},
        {"vertexGroups", (getter)Armature_getVertexGroups, (setter)Armature_setVertexGroups, 
index 870735e6bf93dc9819e6ad171c5642750908e1a4..4ba55139463a135fd37aa3d5fb8a653445ab5041 100644 (file)
@@ -848,6 +848,10 @@ static int Camera_setName( BPy_Camera * self, PyObject * value )
        return 0;
 }
 
+static PyObject *Camera_getLib( BPy_Camera * self )
+{
+       return EXPP_GetIdLib((ID *)self->camera);
+}
 
 static PyObject *Camera_getUsers( BPy_Camera * self )
 {
@@ -1119,6 +1123,10 @@ static PyGetSetDef BPy_Camera_getseters[] = {
         (getter)Camera_getName, (setter)Camera_setName,
         "Camera name",
         NULL},
+       {"lib",
+        (getter)Camera_getLib, (setter)NULL,
+        "Camera libname",
+        NULL},
        {"users",
         (getter)Camera_getUsers, (setter)NULL,
         "Number of camera users",
index 777d0317c38b2e4648dcc79572da2d626fd4abab..b8be14886e20b9300c868fd507aba6d35d92aa79 100644 (file)
@@ -1550,6 +1550,11 @@ static PyObject *CurveGetAttr( BPy_Curve * self, char *name )
 
        if( strcmp( name, "name" ) == 0 )
                attr = PyString_FromString( self->curve->id.name + 2 );
+       else if( strcmp( name, "lib" ) == 0 )
+               /* WARNING - Not standard, until we move to get/setattrs
+                  at the moment we cant return None at the end because it raises an error */
+               attr = EXPP_GetIdLib((ID *)self->curve);
+               if (attr) return attr; 
        else if( strcmp( name, "pathlen" ) == 0 )
                attr = PyInt_FromLong( self->curve->pathlen );
        else if( strcmp( name, "totcol" ) == 0 )
index bb9b700727aad73ef4fe5326d2f0294409e84406..660b1225eb7a38656c3247e1ed9e5ed7d6a271c8 100644 (file)
@@ -242,6 +242,11 @@ static int Font_setFilename( BPy_Font * self, PyObject * value )
 }
 
 
+static PyObject *Font_getLib( BPy_Font * self )
+{
+       return EXPP_GetIdLib((ID *)self->font);
+}
+
 /*--------------- BPy_Font.pack()---------------------------------*/
 static PyObject *Font_pack( BPy_Font * self ) 
 {
@@ -291,14 +296,18 @@ static PyGetSetDef BPy_Font_getseters[] = {
         (getter)Font_getName, (setter)Font_setName,
         "Font name",
         NULL},
-       {"filename",
-        (getter)Font_getFilename, (setter)Font_setFilename,
-        "Font filepath",
+       {"lib",
+        (getter)Font_getLib, (setter)NULL,
+        "Font linked library",
         NULL},
        {"users",
         (getter)Font_getUsers, (setter)NULL,
         "Number of font users",
         NULL},
+       {"filename",
+        (getter)Font_getFilename, (setter)Font_setFilename,
+        "Font filepath",
+        NULL},
        {"packed",
         (getter)Font_getPacked, (setter)NULL,
         "Packed status",
index 33465574f7953de60cefddfc19bb7d3328ce6248..4fb3a4c099b190f8f1dd0aaf6f0b9751abe8f5fb 100755 (executable)
@@ -245,6 +245,13 @@ static PyObject *Group_getName( BPy_Group * self )
                                        "couldn't get Group.name attribute" ) );
 }
 
+static PyObject *Group_getLib( BPy_Group * self )
+{
+       GROUP_DEL_CHECK_PY(self);
+       return EXPP_GetIdLib((ID *)self->group);
+       
+}
+
 static PyObject *Group_getUsers( BPy_Group * self )
 {
        GROUP_DEL_CHECK_PY(self);
@@ -306,6 +313,10 @@ static PyGetSetDef BPy_Group_getseters[] = {
         (getter)Group_getName, (setter)Group_setName,
         "Group name",
         NULL},
+       {"lib",
+        (getter)Group_getLib, (setter)NULL,
+        "Group linked library",
+        NULL},
        {"users",
         (getter)Group_getUsers, (setter)NULL,
         "Number of group users",
index 20b8054dfede04145924f724299f5fd0fe7dccba..a5b5642865d62eca7d025b76a6c0a04b56f6ec54 100644 (file)
@@ -1140,35 +1140,39 @@ static PyObject *Image_getAttr( BPy_Image * self, char *name )
        else if( strcmp( name, "packed" ) == 0 ) {
                if (self->image->packedfile) attr = Py_True;
                else attr = Py_False;
-               EXPP_incr_ret(attr);
+               Py_INCREF(attr);
        } else if( strcmp( name, "has_data" ) == 0 ) {
                if (self->image->ibufs.first) attr = Py_True;
                else attr = Py_False;
-               EXPP_incr_ret(attr);
+               Py_INCREF(attr);
        } else if( strcmp( name, "fields" ) == 0 ) {
                if (self->image->flag & IMA_FIELDS) attr = Py_True;
                else attr = Py_False;
-               EXPP_incr_ret(attr);
+               Py_INCREF(attr);
        } else if( strcmp( name, "fields_odd" ) == 0 ) {
                if (self->image->flag & IMA_STD_FIELD) attr = Py_True;
                else attr = Py_False;
-               EXPP_incr_ret(attr);
+               Py_INCREF(attr);
        } else if( strcmp( name, "antialias" ) == 0 ) {
                if (self->image->flag & IMA_ANTIALI) attr = Py_True;
                else attr = Py_False;
-               EXPP_incr_ret(attr);
-               
+               Py_INCREF(attr);
+       } else if ( strcmp( name, "lib" ) == 0 ) {
+               /* WARNING - Not standard, until we move to get/setattrs
+                  at the moment we cant return None at the end because it raises an error */
+               attr = EXPP_GetIdLib((ID *)self->image);
+               if (attr) return attr; 
        } else if( strcmp( name, "bindcode" ) == 0 )
                attr = PyInt_FromLong( self->image->bindcode );
        else if( strcmp( name, "users" ) == 0 )
                attr = PyInt_FromLong( self->image->id.us );
        else if( strcmp( name, "__members__" ) == 0 )
-               attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
+               attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
                                      "name", "filename", "size", "depth",
                                      "xrep", "yrep", "start", "end",
                                      "speed", "packed", "has_data"
                                      "fields", "odd", "antialias",
-                                         "bindcode", "users" );
+                                         "bindcode", "users", "lib" );
 
        if( !attr )
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
index 6a36079371b245242ed7bc7f48eea99ba1978e0e..e546a1932da712dec9b337104d097c33fc29cc64 100644 (file)
@@ -101,6 +101,8 @@ static PyObject *Ipo_getRctf( BPy_Ipo * self );
 static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args );
 static int Ipo_setRctf( BPy_Ipo * self, PyObject * args );
 
+static PyObject *Ipo_getLib( BPy_Ipo * self );
+static PyObject *Ipo_getUsers( BPy_Ipo * self );
 static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
 static PyObject *Ipo_getCurves( BPy_Ipo * self );
 static PyObject *Ipo_getCurveNames( BPy_Ipo * self );
@@ -119,6 +121,9 @@ static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args );
 static PyObject *Ipo_getChannel( BPy_Ipo * self );
 static int Ipo_setChannel( BPy_Ipo * self, PyObject * args );
 
+static PyObject *Ipo_getFakeUser( BPy_Ipo * self );
+static int Ipo_setFakeUser( BPy_Ipo * self, PyObject * value );
+
 static int Ipo_length( BPy_Ipo * inst );
 static PyObject *Ipo_getIpoCurveByName( BPy_Ipo * self, PyObject * key );
 static int Ipo_setIpoCurveByName( BPy_Ipo * self, PyObject * key, 
@@ -177,6 +182,18 @@ static PyGetSetDef BPy_Ipo_getseters[] = {
         (getter)Ipo_getName, (setter)Ipo_setName,
         "Ipo data name",
         NULL},
+       {"lib",
+        (getter)Ipo_getLib, (setter)NULL,
+        "Ipos linked library",
+        NULL},
+       {"users",
+        (getter)Ipo_getUsers, (setter)NULL,
+        "Number of Ipo users",
+        NULL},
+       {"fakeUser",
+        (getter)Ipo_getFakeUser, (setter)Ipo_setFakeUser,
+        "Ipos fake user state",
+        NULL},
        {"curves",
         (getter)Ipo_getCurves, (setter)NULL,
         "Ipo curves",
@@ -227,7 +244,7 @@ static PySequenceMethods Ipo_as_sequence = {
 /* Python Ipo_Type callback function prototypes:                             */
 /*****************************************************************************/
 static void Ipo_dealloc( BPy_Ipo * self );
-//static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);
+/*static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);*/
 static int Ipo_compare( BPy_Ipo * a, BPy_Ipo * b );
 static PyObject *Ipo_repr( BPy_Ipo * self );
 static PyObject *Ipo_getIter( BPy_Ipo * self );
@@ -830,6 +847,33 @@ static int Ipo_setName( BPy_Ipo * self, PyObject * args )
        return 0;
 }
 
+
+static PyObject *Ipo_getLib( BPy_Ipo * self )
+{
+       return EXPP_GetIdLib((ID *)self->ipo);
+       
+}
+
+static PyObject *Ipo_getUsers( BPy_Ipo * self )
+{
+       return PyInt_FromLong( self->ipo->id.us );
+}
+
+static PyObject *Ipo_getFakeUser( BPy_Ipo * self )
+{
+       if (self->ipo->id.flag & LIB_FAKEUSER)
+               Py_RETURN_TRUE;
+       else
+               Py_RETURN_FALSE;
+}
+
+static int Ipo_setFakeUser( BPy_Ipo * self, PyObject * value )
+{
+       return SetIdFakeUser(&self->ipo->id, value);
+}
+
+
+
 static PyObject *Ipo_getBlocktype( BPy_Ipo * self )
 {
        PyObject *attr = PyInt_FromLong( self->ipo->blocktype );
@@ -1631,7 +1675,7 @@ static PyObject *Ipo_nextIter( BPy_Ipo * self )
 /*****************************************************************************/
 PyObject *Ipo_Init( void )
 {
-       // PyObject *submodule;
+       /* PyObject *submodule; */
 
        if( PyType_Ready( &Ipo_Type ) < 0 )
                return NULL;
@@ -1822,7 +1866,7 @@ static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
                return ( EXPP_ReturnPyObjError
                         ( PyExc_TypeError, "No IPO curve" ) );
 
-       if( PyNumber_Check( PyTuple_GetItem( args, 0 ) ) )      // args is an integer
+       if( PyNumber_Check( PyTuple_GetItem( args, 0 ) ) )      /* args is an integer */
        {
                if( !PyArg_ParseTuple( args, "i", &numcurve ) )
                        return ( EXPP_ReturnPyObjError
@@ -1837,7 +1881,7 @@ static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
                }
        }
 
-       else                    // args is a string
+       else                    /* args is a string */
        {
                if( !PyArg_ParseTuple( args, "s", &stringname ) )
                        return ( EXPP_ReturnPyObjError
index 0ccc408e434d924cf75c57b8c671d3bc00f35057..e9d5023add938893c5b5f885a2104d6fd3e8d9d9 100644 (file)
@@ -179,6 +179,8 @@ struct PyMethodDef M_Lamp_methods[] = {
 /* Python BPy_Lamp methods declarations:                                     */
 /*****************************************************************************/
 static PyObject *Lamp_getName( BPy_Lamp * self );
+static PyObject *Lamp_getLib( BPy_Lamp * self );
+static PyObject *Lamp_getFakeUser( BPy_Lamp * self );
 static PyObject *Lamp_getType( BPy_Lamp * self );
 static PyObject *Lamp_getTypesConst( void );
 static PyObject *Lamp_getMode( BPy_Lamp * self );
@@ -232,6 +234,7 @@ static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args );
 static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args );
 static int Lamp_setIpo( BPy_Lamp * self, PyObject * args );
 static int Lamp_setName( BPy_Lamp * self, PyObject * args );
+static int Lamp_setFakeUser( BPy_Lamp * self, PyObject * args );
 static int Lamp_setType( BPy_Lamp * self, PyObject * args );
 static int Lamp_setMode( BPy_Lamp * self, PyObject * args );
 static int Lamp_setSamples( BPy_Lamp * self, PyObject * args );
@@ -379,6 +382,22 @@ static PyMethodDef BPy_Lamp_methods[] = {
 /* Python attributes get/set structure:                                      */
 /*****************************************************************************/
 static PyGetSetDef BPy_Lamp_getseters[] = {
+       {"name",
+        (getter)Lamp_getName, (setter)Lamp_setName,
+        "Lamp data name",
+        NULL},
+       {"lib",
+        (getter)Lamp_getLib, (setter)NULL,
+        "Lamps linked library",
+        NULL},
+       {"users",
+        (getter)Lamp_getUsers, (setter)NULL,
+        "Number of lamp users",
+        NULL},
+       {"fakeUser",
+        (getter)Lamp_getFakeUser, (setter)Lamp_setFakeUser,
+        "Lamps fake user state",
+        NULL},
        {"bias",
         (getter)Lamp_getBias, (setter)Lamp_setBias,
         "Lamp shadow map sampling bias",
@@ -423,10 +442,6 @@ static PyGetSetDef BPy_Lamp_getseters[] = {
         (getter)Lamp_getMode, (setter)Lamp_setMode,
         "Lamp mode bitmask",
         NULL},
-       {"name",
-        (getter)Lamp_getName, (setter)Lamp_setName,
-        "Lamp data name",
-        NULL},
        {"quad1",
         (getter)Lamp_getQuad1, (setter)Lamp_setQuad1,
         "Quad lamp linear distance attenuation",
@@ -495,10 +510,6 @@ static PyGetSetDef BPy_Lamp_getseters[] = {
         (getter)Lamp_getComponent, (setter)Lamp_setComponent,
         "Lamp color blue component",
         (void *)EXPP_LAMP_COMP_B},
-       {"users",
-        (getter)Lamp_getUsers, (setter)NULL,
-        "Number of lamp users",
-        NULL},
        {"Modes",
         (getter)Lamp_getModesConst, (setter)NULL,
         "Dictionary of values for 'mode' attribute",
@@ -614,7 +625,6 @@ static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
        static char *kwlist[] = { "type_str", "name_str", NULL };
        BPy_Lamp *py_lamp;      /* for Lamp Data object wrapper in Python */
        Lamp *bl_lamp;          /* for actual Lamp Data we create in Blender */
-       char buf[21];
 
        if( !PyArg_ParseTupleAndKeywords( args, keywords, "|ss", kwlist,
                                          &type_str, &name_str ) )
@@ -907,6 +917,19 @@ static PyObject *Lamp_getName( BPy_Lamp * self )
                                        "couldn't get Lamp.name attribute" ) );
 }
 
+static PyObject *Lamp_getLib( BPy_Lamp * self )
+{
+       return EXPP_GetIdLib((ID *)self->lamp);
+}
+
+static PyObject *Lamp_getFakeUser( BPy_Lamp * self )
+{
+       if (self->lamp->id.flag & LIB_FAKEUSER)
+               Py_RETURN_TRUE;
+       else
+               Py_RETURN_FALSE;
+}
+
 static PyObject *Lamp_getType( BPy_Lamp * self )
 {
        PyObject *attr = PyInt_FromLong( self->lamp->type );
@@ -1148,6 +1171,11 @@ static int Lamp_setName( BPy_Lamp * self, PyObject * value )
        return 0;
 }
 
+static int Lamp_setFakeUser( BPy_Lamp * self, PyObject * value )
+{
+       return SetIdFakeUser(&self->lamp->id, value);
+}
+
 static int Lamp_setType( BPy_Lamp * self, PyObject * value )
 {
        return EXPP_setIValueRange ( value, &self->lamp->type,
index 0837773b8a2f29a58be4206df20e5e0f1dfea29e..c0551034eb8c40ce8d11d78d50a3f50657f3d00d 100644 (file)
@@ -747,7 +747,12 @@ static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
        
        if( strcmp( name, "name" ) == 0 )
                attr = PyString_FromString( self->Lattice->id.name + 2 );
-       else if( strcmp( name, "width" ) == 0 )
+       else if ( strcmp( name, "lib" ) == 0 ) {
+               /* WARNING - Not standard, until we move to get/setattrs
+                  at the moment we cant return None at the end because it raises an error */
+               attr = EXPP_GetIdLib((ID *)self->Lattice);
+               if (attr) return attr;
+       } else if( strcmp( name, "width" ) == 0 )
                attr = PyInt_FromLong( self->Lattice->pntsu );
        else if( strcmp( name, "height" ) == 0 )
                attr = PyInt_FromLong( self->Lattice->pntsv );
@@ -800,10 +805,10 @@ static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
        } else if( strcmp( name, "key" ) == 0 ) {
                return Lattice_getKey(self);
        } else if( strcmp( name, "__members__" ) == 0 )
-               attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s]", "name", "width",
+               attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s]", "name", "width",
                                      "height", "depth", "widthType",
                                      "heightType", "depthType", "mode",
-                                     "latSize", "users", "key" );
+                                     "latSize", "users", "key", "lib" );
        
        if( !attr )
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
index 5d5075891ee5cfc562310a12c720e49c936b63b4..4a22540a0ae3534dbe54d72b8998dc402b826259 100644 (file)
@@ -66,6 +66,7 @@ static PyObject *M_Library_Update( PyObject * self );
 static PyObject *M_Library_Datablocks( PyObject * self, PyObject * args );
 static PyObject *M_Library_Load( PyObject * self, PyObject * args );
 static PyObject *M_Library_LinkableGroups( PyObject * self );
+static PyObject *M_Library_LinkedLibs( PyObject * self );
 
 PyObject *Library_Init( void );
 void EXPP_Library_Close( void );
@@ -112,6 +113,9 @@ for each loaded object.";
 static char Library_LinkableGroups_doc[] =
        "() - Get all linkable groups from the open .blend library file.";
 
+static char Library_LinkedLibs_doc[] =
+       "() - Get all libs used in the the open .blend file.";
+       
 /**
  * Python method structure definition for Blender.Library submodule.
  */
@@ -128,6 +132,8 @@ struct PyMethodDef M_Library_methods[] = {
        {"Load", M_Library_Load, METH_VARARGS, Library_Load_doc},
        {"LinkableGroups", ( PyCFunction ) M_Library_LinkableGroups,
         METH_NOARGS, Library_LinkableGroups_doc},
+       {"LinkedLibs", ( PyCFunction ) M_Library_LinkedLibs,
+        METH_NOARGS, Library_LinkedLibs_doc},
        {NULL, NULL, 0, NULL}
 };
 
@@ -293,22 +299,36 @@ PyObject *M_Library_LinkableGroups( PyObject * self )
        }
 
        names = BLO_blendhandle_get_linkable_groups( bpy_openlib );
-
+       list = PyList_New( BLI_linklist_length( names ) );
+       
        if( names ) {
                int counter = 0;
-               list = PyList_New( BLI_linklist_length( names ) );
+               
                for( l = names; l; l = l->next ) {
-                       PyList_SET_ITEM( list, counter,
-                                        Py_BuildValue( "s",
-                                                       ( char * ) l->link ) );
+                       PyList_SET_ITEM( list, counter, PyString_FromString( ( char * ) l->link  ) );
                        counter++;
                }
                BLI_linklist_free( names, free );       /* free linklist *and* each node's data */
                return list;
        }
+       return list;
+}
 
-       Py_INCREF( Py_None );
-       return Py_None;
+/**
+ * Return a list with the names of all externally linked libs used in the current Blend file
+ */
+PyObject *M_Library_LinkedLibs( PyObject * self )
+{
+       int counter = 0;
+       Library *li;
+       PyObject *list;
+
+       list = PyList_New( BLI_countlist( &( G.main->library ) ) );
+       for (li= G.main->library.first; li; li= li->id.next) {
+               PyList_SET_ITEM( list, counter, PyString_FromString( li->name ));
+               counter++;
+       }
+       return list;
 }
 
 /**
index 580e5e6355557bc9c744335d39e7d0b5816d3c9a..6fceec1f4855a0e6fddccc531190a1519143c793 100644 (file)
@@ -36,6 +36,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h" /* MainSeq_new */
 #include "DNA_texture_types.h"
+#include "DNA_curve_types.h"
 #include "DNA_ipo_types.h"
 #include "DNA_group_types.h"
 #include "DNA_world_types.h"
@@ -74,7 +75,8 @@
 #include "Camera.h"
 #include "Armature.h"
 #include "Lamp.h"
-#include "CurNurb.h"
+/*#include " CurNurb.h" do we need this ? */
+#include "Curve.h"
 #include "NMesh.h"
 #include "Mesh.h"
 #include "Lattice.h"
index b8de13637ec9e0a31d8b6a67ace353e734017745..82b9371e4f1d68a0b893439e7fb9c605ecf46f41 100644 (file)
@@ -533,6 +533,7 @@ static PyObject *Material_getColorComponent( BPy_Material * self,
                                                        void * closure );
 static PyObject *Material_getOopsLoc( BPy_Material * self );
 static PyObject *Material_getOopsSel( BPy_Material * self );
+static PyObject *Material_getLib( BPy_Material * self );
 static PyObject *Material_getUsers( BPy_Material * self );
 static PyObject *Material_getFakeUser( BPy_Material * self );
 /*static int Material_setSeptex( BPy_Material * self, PyObject * value );
@@ -1092,6 +1093,10 @@ static PyGetSetDef BPy_Material_getseters[] = {
         (getter)Material_getFakeUser, (setter)Material_setFakeUser,
         "The fake user status of this material",
         NULL},
+       {"lib",
+        (getter)Material_getLib, (setter)NULL,
+        "Materials external library",
+        NULL},
         {"properties", (getter) Material_getProperties, (setter)NULL,
         "Get material's ID properties"},
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
@@ -2845,6 +2850,11 @@ static int Material_setOopsSel ( BPy_Material * self, PyObject * value )
        return 0;
 }
 
+static PyObject *Material_getLib(BPy_Material *self)
+{
+       return EXPP_GetIdLib((ID *)self->material);
+}
+
 static PyObject *Material_getUsers( BPy_Material * self )
 {
        return PyInt_FromLong( self->material->id.us );
index d2e68b426c76438081cc1ef90a42e3842978e7ff..98396a743ca8b87340fde4515d297b1091698efd 100644 (file)
@@ -7195,6 +7195,11 @@ static PyObject *Mesh_getUsers( BPy_Mesh * self )
                                        "couldn't get Mesh.users attribute" );
 }
 
+static PyObject *Mesh_getLib(BPy_Mesh *self)
+{
+       return EXPP_GetIdLib((ID *)self->mesh);
+}
+
 static PyObject *Mesh_getFakeUser( BPy_Mesh * self )
 {
        if (self->mesh->id.flag & LIB_FAKEUSER)
@@ -7661,6 +7666,10 @@ static PyGetSetDef BPy_Mesh_getseters[] = {
         (getter)Mesh_getUsers, (setter)NULL,
         "Number of users of the mesh",
         NULL},
+       {"lib",
+        (getter)Mesh_getLib, (setter)NULL,
+        "Meshes external library",
+        NULL},
        {"fakeUser",
         (getter)Mesh_getFakeUser, (setter)Mesh_setFakeUser,
         "The fake user status of this mesh",
index e2f2c33610635ee1a49928a4c29c570e0d187818..1de71e160ac5b67664cc596fcf1e2c581fc87d8f 100644 (file)
@@ -107,6 +107,7 @@ static PyObject *M_MetaElem_TypesDict( void )
 /*****************************************************************************/
 static PyObject *Metaball_getElements( BPy_Metaball * self );
 static PyObject *Metaball_getName( BPy_Metaball * self );
+static PyObject *Metaball_getLib( BPy_Metaball * self );
 static int Metaball_setName( BPy_Metaball * self, PyObject * value );
 static PyObject *Metaball_getMaterials( BPy_Metaball * self );
 static int Metaball_setMaterials( BPy_Metaball * self, PyObject * value );
@@ -176,6 +177,10 @@ static PyGetSetDef BPy_Metaball_getseters[] = {
         (getter)Metaball_getName, (setter)Metaball_setName,
         "Metaball name",
         NULL},
+       {"lib",
+        (getter)Metaball_getLib, (setter)NULL,
+        "Metaballs external library",
+        NULL},
        {"users",
         (getter)Metaball_getUsers, (setter)NULL,
         "Number of metaball users",
@@ -557,8 +562,6 @@ static PyObject *Metaball_getName( BPy_Metaball * self )
                                        "couldn't get Metaball.name attribute" ) );
 }
 
-
-
 static int Metaball_setName( BPy_Metaball * self, PyObject * value )
 {
        char *name = NULL;
@@ -571,6 +574,11 @@ static int Metaball_setName( BPy_Metaball * self, PyObject * value )
        return 0;
 }
 
+static PyObject *Metaball_getLib( BPy_Metaball * self )
+{
+       return EXPP_GetIdLib((ID *)self->metaball);
+}
+
 static PyObject *Metaball_getMaterials( BPy_Metaball *self )
 {
        return EXPP_PyList_fromMaterialList( self->metaball->mat,
index 9f7d8f7502342f3050415a612b259764a8524fee..1593fa2ed1e7a260fc205db0a61e9f04c87f9667 100644 (file)
@@ -347,6 +347,7 @@ static PyObject *Object_getLocation( BPy_Object * self, PyObject * args );
 static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args );
 static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args );
 static PyObject *Object_getName( BPy_Object * self );
+static PyObject *Object_getLib( BPy_Object * self );
 static PyObject *Object_getParent( BPy_Object * self );
 static PyObject *Object_getParentBoneName( BPy_Object * self );
 static int Object_setParentBoneName( BPy_Object * self, PyObject * value );
@@ -1323,6 +1324,11 @@ static PyObject *Object_getName( BPy_Object * self )
        return PyString_FromString( self->object->id.name + 2 );
 }
 
+static PyObject *Object_getLib( BPy_Object * self )
+{
+       return EXPP_GetIdLib((ID *)self->object);
+}
+
 static PyObject *Object_getParent( BPy_Object * self )
 {
        if( self->object->parent )
@@ -4921,6 +4927,10 @@ static PyGetSetDef BPy_Object_getseters[] = {
         (getter)Object_getName, (setter)Object_setName,
         "Object data name",
         NULL},
+       {"lib",
+        (getter)Object_getLib, (setter)NULL,
+        "Objects linked library",
+        NULL},
        {"oopsLoc",
         (getter)Object_getOopsLoc, (setter)Object_setOopsLoc,
         "Object OOPs location",
index fdea1aa8ca213abd403fede034f98052e3cd9bed..5279142c03b02ff02fe46f4a5008ea1e0d25ef06 100644 (file)
@@ -294,7 +294,10 @@ static PyObject *Scene_getAttr( BPy_Scene * self, char *name )
 
        else if ( strcmp( name, "properties" ) == 0 )
                return BPy_Wrap_IDProperty( (ID*)self->scene, IDP_GetProperties((ID*)self->scene, 1), NULL );
-
+       
+       else if ( strcmp( name, "lib" ) == 0 )
+               return EXPP_GetIdLib((ID *)self->scene);
+       
        /* accept both Layer (for compatibility with ob.Layer) and Layers */
        else if( strncmp( name, "Layer", 5 ) == 0 )
                attr = PyInt_FromLong( self->scene->lay & ((1<<20)-1) );
@@ -305,7 +308,7 @@ static PyObject *Scene_getAttr( BPy_Scene * self, char *name )
                return Scene_getObjects(self);
 
        else if( strcmp( name, "__members__" ) == 0 )
-               attr = Py_BuildValue( "[sss]", "name", "Layers", "layers", "objects");
+               attr = Py_BuildValue( "[ssssss]", "name", "Layers", "layers", "objects", "properties", "lib");
 
        if( !attr )
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
index 3f0cea118d449a62f3107a8b0d41699e293da9c1..ce0e4cbfda5ef4590774e826e7d5cdee4858e840 100644 (file)
@@ -551,6 +551,8 @@ static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
                attr = PyString_FromString( self->sound->id.name + 2 );
        else if( strcmp( name, "filename" ) == 0 )
                attr = PyString_FromString( self->sound->name );
+       else if( strcmp( name, "lib" ) == 0 )
+               return EXPP_GetIdLib((ID *)self->sound);
        else if( strcmp( name, "packed" ) == 0 ) {
                if (!sound_sample_is_null(self->sound))
                {
@@ -563,7 +565,7 @@ static PyObject *Sound_getAttr( BPy_Sound * self, char *name )
                else
                        attr = EXPP_incr_ret_False();
        } else if( strcmp( name, "__members__" ) == 0 )
-               attr = Py_BuildValue( "[s,s]", "name", "filename" );
+               attr = Py_BuildValue( "[s,s,s]", "name", "filename", "lib", "packed" );
        
        if( !attr )
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
index e4fb48ed20d897ba870b19993195480dbc845a9a..6400f3a716e217186ab1efa5aa8ec54c3e50f1a7 100644 (file)
@@ -934,6 +934,8 @@ static PyObject *World_GetAttr( BPy_World * self, char *name )
 
        if( strcmp( name, "name" ) == 0 )
                return World_getName( self );
+       if( strcmp( name, "lib" ) == 0 )
+               return EXPP_GetIdLib((ID *)self->world);
        if( strcmp( name, "skytype" ) == 0 )
                return World_getSkytype( self );
        if( strcmp( name, "mode" ) == 0 )
index 641992ecb4390faa443390a84f6af56f7e7b2628..01cf7c461bc305dace1473f1818fddd07ef9f8a4 100644 (file)
@@ -185,7 +185,17 @@ int SetIdFakeUser( ID * id, PyObject *value)
        return 0;
 }
 
-
+/*****************************************************************************/
+/* Description: This function sets the fake user status of the ID            */
+/* returns an int error, so from getsetattrs                                 */
+/*****************************************************************************/
+PyObject *EXPP_GetIdLib( ID * id )
+{
+       if (id->lib)
+               return PyString_FromString(id->lib->name);
+       else
+               return EXPP_incr_ret( Py_None );
+}
 
 /*****************************************************************************/
 /* Description: These functions set an internal string with the given type   */
index 488975ce31ce70f83750f0f4a3bce9f86346dd95..f464e626390ea1338600609081481734f50e843a 100644 (file)
@@ -69,6 +69,7 @@ PyObject *EXPP_GetModuleConstant(char *module, char *constant);
 
 int StringEqual( const char *string1, const char *string2 );
 char *GetIdName( ID * id );
+PyObject *EXPP_GetIdLib( ID * id );
 int SetIdFakeUser( ID * id, PyObject *value);
 
 ID *GetIdFromList( ListBase * list, char *name );