[Durian-svn] [2255] option to fix image paths

campbell institute at blender.org
Wed Apr 21 11:27:48 CEST 2010


Revision: 2255
          https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=2255
Author:   campbell
Date:     2010-04-21 11:27:48 +0200 (Wed, 21 Apr 2010)
Log Message:
-----------
option to fix image paths

Modified Paths:
--------------
    pro/scripts/utilities/findPathError.py

Modified: pro/scripts/utilities/findPathError.py
===================================================================
--- pro/scripts/utilities/findPathError.py	2010-04-21 09:25:19 UTC (rev 2254)
+++ pro/scripts/utilities/findPathError.py	2010-04-21 09:27:48 UTC (rev 2255)
@@ -31,15 +31,30 @@
 expandpath = bpy.utils.expandpath
 from os.path import exists
 
+DUMMY_NAMES = ('Viewer Node', 'Render Result', 'Untitled')
+
+def ignore_image(image):
+    if image.source in ('GENERATED', 'VIEWER'):
+        return True
+
+    name = image.name
+
+    if name in DUMMY_NAMES or os.path.splitext(name)[0] in DUMMY_NAMES:
+        return True
+    
+    return False
+
+
+
 def report_images():
-    DUMMY_NAMES = ('Viewer Node', 'Render Result', 'Untitled')
+    
 
     image_duplicates = {}
 
     for i in bpy.data.images:
         if not i.library:
             name = i.name
-            if name in DUMMY_NAMES or os.path.splitext(name)[0] in DUMMY_NAMES:
+            if ignore_image(i):
                 continue
             
             filename = i.filename
@@ -82,6 +97,26 @@
                     if not exists(filename_abs):
                         print("ERROR PATH:", obj.name, filename, 'ABS:', filename_abs, "(OBJECT MODIFIER)")
 
+
+def make_relative():
+    change = False
+    for i in bpy.data.images:
+        if not i.library:
+            if ignore_image(i):
+                continue
+
+            filename = i.filename
+            if not filename.startswith("//"):
+                # make relative
+                i.filename = bpy.utils.relpath(filename)
+                change = True
+
+    if change:
+        bpy.ops.wm.save_mainfile()
+
 if __name__ == "__main__":
     report_images()
-    report_modifiers()
\ No newline at end of file
+    report_modifiers()
+    
+    # optional, take care!
+    make_relative()



More information about the Durian-svn mailing list