[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14648] trunk/blender/source/blender/ python/api2_2x: Add library.name attribute, which returns the actual library name used by blender ( this may be different from the library.filename attribute).

Ken Hughes khughes at pacific.edu
Thu May 1 20:52:26 CEST 2008


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

Log Message:
-----------
Add library.name attribute, which returns the actual library name used by blender (this may be different from the library.filename attribute).

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 18:46:50 UTC (rev 14647)
+++ trunk/blender/source/blender/python/api2_2x/Library.c	2008-05-01 18:52:26 UTC (rev 14648)
@@ -977,6 +977,39 @@
 	return 0;
 }
 
+/*
+ * Return the library's name.  The format depends on whether the library is 
+ * accessed as relative or absolute.
+ */
+
+static PyObject *Library_getName( BPy_Library * self )
+{
+	Library *lib;
+	BlendHandle *openlib;
+	char longFilename[FILE_MAX];
+
+	/* try to open the library */
+	openlib = open_library( self->filename, longFilename );
+	if( openlib ) {
+		BLO_blendhandle_close( openlib );
+		/* remove any /../ or /./ junk */
+		BLI_cleanup_file(NULL, longFilename); 
+
+		/* search the loaded libraries for a match */
+		for( lib = G.main->library.first; lib; lib = lib->id.next )
+			if( strcmp( longFilename, lib->filename ) == 0) {
+				return PyString_FromString( lib->name );
+			}
+
+		/* library not found in memory */
+		return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+				"library not loaded" );
+	}
+	/* could not load library */
+	return EXPP_ReturnPyObjError( PyExc_IOError, "library not found" );
+}
+
+
 /************************************************************************
  * Python Library_type attributes get/set structure
  ************************************************************************/
@@ -986,6 +1019,10 @@
 	 (getter)Library_getFilename, (setter)Library_setFilename,
 	 "library filename",
 	 NULL},
+	{"name",
+	 (getter)Library_getName, (setter)NULL,
+	 "library name (as used by Blender)",
+	 NULL},
 	{"objects",
 	 (getter)LibraryData_CreatePyObject, (setter)NULL,
 	 "objects from the library",

Modified: trunk/blender/source/blender/python/api2_2x/doc/LibData.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/LibData.py	2008-05-01 18:46:50 UTC (rev 14647)
+++ trunk/blender/source/blender/python/api2_2x/doc/LibData.py	2008-05-01 18:52:26 UTC (rev 14648)
@@ -33,9 +33,8 @@
   
   @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.
+  @type relative: boolean
+  @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.
   """
@@ -49,8 +48,10 @@
 	It provides access to scenes, objects, meshes, curves, metaballs,
 	materials, textures, images, lattices, lamps, cameras, ipos, worlds,
 	fonts, texts, sounds, groups, armatures, and actions.
-	@ivar filename: The path to the library
+	@ivar filename: The filename of the library, as supplied by user.
 	@type filename: string
+	@ivar name: The path to the library, as used by Blender.  If the filename supplied by the user is relative, but the relative option to L{library.load()<load>} is False, the name will be the absolute path.
+	@type name: string
 	@ivar scenes: library L{scene<Scene.Scene>} data
 	@type scenes: L{LibData}
 	@ivar objects: library L{object<Object.Object>} data





More information about the Bf-blender-cvs mailing list