[Bf-extensions-cvs] [7aef9ab] master: New Tool: Collect images.

Eugenio Pignataro noreply at git.blender.org
Mon Apr 3 16:24:03 CEST 2017


Commit: 7aef9abb9dd1b1939f8256151ad77d34a3554bc0
Author: Eugenio Pignataro
Date:   Mon Apr 3 11:23:54 2017 -0300
Branches: master
https://developer.blender.org/rBA7aef9abb9dd1b1939f8256151ad77d34a3554bc0

New Tool: Collect images.

===================================================================

M	oscurart_tools/__init__.py
M	oscurart_tools/oscurart_files.py

===================================================================

diff --git a/oscurart_tools/__init__.py b/oscurart_tools/__init__.py
index 5708218..87ff68b 100644
--- a/oscurart_tools/__init__.py
+++ b/oscurart_tools/__init__.py
@@ -291,6 +291,7 @@ class OscPanelFiles(Panel):
         col = layout.column(align=1)
         col.operator("file.save_incremental_osc", icon="NEW")
         col.operator("image.reload_images_osc", icon="IMAGE_COL")
+        col.operator("file.collect_all_images", icon="IMAGE_COL")
         col.operator("file.sync_missing_groups", icon="LINK_AREA")
         col = layout.column(align=1)
         colrow = col.row(align=1)
diff --git a/oscurart_tools/oscurart_files.py b/oscurart_tools/oscurart_files.py
index 9582b8e..f22c833 100644
--- a/oscurart_tools/oscurart_files.py
+++ b/oscurart_tools/oscurart_files.py
@@ -21,13 +21,14 @@
 import bpy
 from bpy.types import Operator
 import os
+import shutil
 
 
 # ---------------------------RELOAD IMAGES------------------
 
 
 class reloadImages (Operator):
-    """Reloads all bitmaps in the scene"""
+    """Reloads all bitmaps in the scene."""
     bl_idname = "image.reload_images_osc"
     bl_label = "Reload Images"
     bl_options = {"REGISTER", "UNDO"}
@@ -41,7 +42,7 @@ class reloadImages (Operator):
 # ------------------------ SAVE INCREMENTAL ------------------------
 
 class saveIncremental(Operator):
-    """Saves incremental version of the blend file Ex: '_v01' '_v02'"""
+    """Saves incremental version of the blend file Ex: “_v01” "_v02"."""
     bl_idname = "file.save_incremental_osc"
     bl_label = "Save Incremental File"
     bl_options = {"REGISTER", "UNDO"}
@@ -72,8 +73,7 @@ bpy.types.Scene.oscReplaceText = bpy.props.StringProperty(
 
 
 class replaceFilePath(Operator):
-    """Replace the paths set on the “search test” field by the ones in “replace” field. """ \
-    """'_v01' »» '_v02' /folder1/render_v01.png  »» /folder1/render_v02.png"""
+    """Replace the paths set on the “search test” field by the ones in “replace” field. "_v01" »» "_v02" /folder1/render_v01.png  »» /folder1/render_v02.png"""
     bl_idname = "file.replace_file_path_osc"
     bl_label = "Replace File Path"
     bl_options = {"REGISTER", "UNDO"}
@@ -91,8 +91,7 @@ class replaceFilePath(Operator):
 # ---------------------- SYNC MISSING GROUPS --------------------------
 
 class reFreshMissingGroups(Operator):
-    """Search on the libraries of the linked source and relink groups and link newones if there are. """ \
-    """Usefull to use with the mesh cache tools"""
+    """Search on the libraries of the linked source and relink groups and link newones if there are. Usefull to use with the mesh cache tools."""
     bl_idname = "file.sync_missing_groups"
     bl_label = "Sync Missing Groups"
     bl_options = {"REGISTER", "UNDO"}
@@ -103,3 +102,35 @@ class reFreshMissingGroups(Operator):
                 with bpy.data.libraries.load(group.library.filepath, link=True) as (linked, local):
                     local.groups = linked.groups
         return {'FINISHED'}
+    
+    
+# ---------------------- COLLECT IMAGES --------------------------   
+
+
+class collectImagesOsc(Operator):
+    """Collect all images in the blend file and put them in IMAGES folder."""
+    bl_idname = "file.collect_all_images"
+    bl_label = "Collect Images"
+    bl_options = {"REGISTER", "UNDO"}
+
+    def execute(self, context):
+        
+        imagespath = "%s/IMAGES"  % (os.path.dirname(bpy.data.filepath))
+        
+        if not os.path.exists(imagespath):
+            os.mkdir(imagespath)
+
+        bpy.ops.file.make_paths_absolute()
+
+        for image in bpy.data.images:
+            if not os.path.exists(os.path.join(imagespath,os.path.basename(image.filepath))):
+                shutil.copy(image.filepath, os.path.join(imagespath,os.path.basename(image.filepath)))
+                image.filepath = os.path.join(imagespath,os.path.basename(image.filepath))
+            else:
+                os.remove(os.path.join(imagespath,os.path.basename(image.filepath)))    
+                shutil.copy(image.filepath, os.path.join(imagespath,os.path.basename(image.filepath)))
+                image.filepath = os.path.join(imagespath,os.path.basename(image.filepath))
+                
+        bpy.ops.file.make_paths_relative()                
+                
+        return {'FINISHED'}
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list