Revision: 14633
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14633
Author:   khughes
Date:     2008-05-01 07:52:35 +0200 (Thu, 01 May 2008)

Log Message:
-----------
Add support to bpy.library module for relative paths.

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Library.c
    trunk/blender/source/blender/python/api2_2x/doc/LibData.py

Modified: trunk/blender/source/blender/python/api2_2x/Library.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Library.c       2008-05-01 
01:00:01 UTC (rev 14632)
+++ trunk/blender/source/blender/python/api2_2x/Library.c       2008-05-01 
05:52:35 UTC (rev 14633)
@@ -515,11 +515,12 @@
  */
 
 static PyObject *CreatePyObject_LibData( int idtype, int kind,
-               void *name, void *iter, char *filename )
+               void *name, void *iter, char *filename, int rel )
 {
        BPy_LibraryData *seq = PyObject_NEW( BPy_LibraryData, 
&LibraryData_Type);
        seq->iter = iter;               /* the name list (for iterators) */
        seq->type = idtype;             /* the Blender ID type */
+       seq->rel =  rel;                /* relative or absolute library */
        seq->kind = kind;               /* used by Blender Objects */
        seq->name = name;               /* object name, iterator name list, or 
NULL */
                                                        /* save the library 
name */
@@ -560,7 +561,8 @@
                /* otherwise, create a pseudo object ready for appending or 
linking */
 
                return CreatePyObject_LibData( ID_OB, mode, 
-                               BLI_strdupn( name, strlen( name ) ), NULL, 
self->filename );
+                               BLI_strdupn( name, strlen( name ) ), NULL, 
self->filename,
+                               self->rel );
        }
 }
 
@@ -586,6 +588,9 @@
        if( !openlib )
                return NULL;
 
+       /* fix any /foo/../foo/ */
+       BLI_cleanup_file(NULL, longFilename); 
+
        /* find all datablocks for the specified type */
        names = BLO_blendhandle_get_datablock_names ( openlib, self->type ); 
 
@@ -616,15 +621,15 @@
        }
 
        /* import from the libary */
-       BLO_script_library_append( &openlib, longFilename, name, self->type, 
mode,
-                       scene );
+       BLO_script_library_append( &openlib, longFilename, name, self->type, 
+                       mode | self->rel, scene );
 
        /*
         * locate the library.  If this is an append, make the data local.  If 
it
         * is link, we need the library for later
         */
        for( lib = G.main->library.first; lib; lib = lib->id.next )
-               if( strcmp( longFilename, lib->name ) == 0 ) {
+               if( strcmp( longFilename, lib->filename ) == 0) {
                        if( mode != FILE_LINK ) {
                                all_local( lib, 1 );
                                /* important we unset, otherwise these object 
wont
@@ -717,7 +722,7 @@
 
        /* build an iterator object for the name list */
        return CreatePyObject_LibData( self->type, OTHER, names,
-                       names, self->filename );
+                       names, self->filename, self->rel );
 }
 
 /* Return next name. */
@@ -942,7 +947,7 @@
 static PyObject *LibraryData_CreatePyObject( BPy_Library *self, void *mode )
 {
        return CreatePyObject_LibData( GET_INT_FROM_POINTER(mode), OTHER, NULL, 
NULL,
-                       self->filename );
+                       self->filename, self->rel);
 }
 
 /************************************************************
@@ -1066,20 +1071,27 @@
  * actually accessed later. 
  */
 
-static PyObject *M_Library_Load(PyObject *self, PyObject * value)
+static PyObject *M_Library_Load(PyObject *self, PyObject * args)
 {
-       char *filename = PyString_AsString(value);
+       char *filename = NULL;
+       PyObject *relative = NULL;
        BPy_Library *lib;
 
-       if( !filename )
+       if( !PyArg_ParseTuple( args, "s|O", &filename, &relative ) )
                return EXPP_ReturnPyObjError( PyExc_TypeError,
-                       "expected a string" );
+                       "expected strings and optional bool as arguments." );
 
        /* try to create a new object */
        lib = (BPy_Library *)PyObject_NEW( BPy_Library, &Library_Type );
        if( !lib )
                return NULL;
 
+       /* save relative flag value */
+       if( relative && PyObject_IsTrue(relative) )
+               lib->rel = FILE_STRINGCODE;
+       else
+               lib->rel = 0;
+
        /* assign the library filename for future use, then return */
        BLI_strncpy( lib->filename, filename, sizeof(lib->filename) );
 
@@ -1087,7 +1099,7 @@
 }
 
 static struct PyMethodDef M_Library_methods[] = {
-       {"load", (PyCFunction)M_Library_Load, METH_O,
+       {"load", (PyCFunction)M_Library_Load, METH_VARARGS,
        "(string) - declare a .blend file for use as a library"},
        {NULL, NULL, 0, NULL}
 };

Modified: trunk/blender/source/blender/python/api2_2x/doc/LibData.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/LibData.py  2008-05-01 
01:00:01 UTC (rev 14632)
+++ trunk/blender/source/blender/python/api2_2x/doc/LibData.py  2008-05-01 
05:52:35 UTC (rev 14633)
@@ -26,13 +26,16 @@
        me.materials[0] = mat                             # assign linked 
material to mesh
 """
 
-def load(filename):
+def load(filename,relative=False):
   """
   Select an existing .blend file for use as a library.  Unlike the 
   Library module, multiple libraries can be defined at the same time.  
   
   @type filename: string
   @param filename: The filename of a Blender file. Filenames starting with 
"//" will be loaded relative to the blend file's location.
+  @type relative: int
+  @param relative: Convert relative paths to absolute paths (default).
+Setting this parameter to True will leave paths relative.
   @rtype: Library
   @return: return a L{Library} object.
   """


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to