[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28321] trunk/blender/release/scripts/ modules/bpy/utils.py: py api.

Campbell Barton ideasman42 at gmail.com
Wed Apr 21 11:27:37 CEST 2010


Revision: 28321
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28321
Author:   campbellbarton
Date:     2010-04-21 11:27:36 +0200 (Wed, 21 Apr 2010)

Log Message:
-----------
py api. bpy.utils.relpath() function.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2010-04-21 07:59:16 UTC (rev 28320)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2010-04-21 09:27:36 UTC (rev 28321)
@@ -205,12 +205,30 @@
 
 
 def expandpath(path):
+    """
+    Returns the absolute path relative to the current blend file using the "//" prefix.
+    """
     if path.startswith("//"):
         return _os.path.join(_os.path.dirname(_bpy.data.filename), path[2:])
 
     return path
 
 
+def relpath(path, start=None):
+    """
+    Returns the path relative to the current blend file using the "//" prefix.
+
+    :arg start: Relative to this path, when not set the current filename is used.
+    :type start: string
+    """
+    if not path.startswith("//"):
+        if start is None:
+            start = _os.path.dirname(_bpy.data.filename)
+        return "//" + _os.path.relpath(path, start)
+
+    return path
+
+
 _unclean_chars = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, \
     17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, \
     35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 58, 59, 60, 61, 62, 63, \





More information about the Bf-blender-cvs mailing list