diff options
author | Eugenio Pignataro <info@oscurart.com.ar> | 2018-12-21 17:32:12 +0300 |
---|---|---|
committer | Eugenio Pignataro <info@oscurart.com.ar> | 2018-12-21 17:32:12 +0300 |
commit | 1f36b19604c4b62ac6acf47f93ad5863af2032de (patch) | |
tree | feb1aba800597300d202160e0ce5908883db2a69 /oscurart_tools/files | |
parent | 7fbe716603d46e6718893c15fe9548e0f1ff646f (diff) |
Add Oscurart Tools for 2.8
Diffstat (limited to 'oscurart_tools/files')
-rw-r--r-- | oscurart_tools/files/collect_images.py | 59 | ||||
-rw-r--r-- | oscurart_tools/files/reload_images.py | 37 | ||||
-rw-r--r-- | oscurart_tools/files/save_incremental.py | 70 |
3 files changed, 166 insertions, 0 deletions
diff --git a/oscurart_tools/files/collect_images.py b/oscurart_tools/files/collect_images.py new file mode 100644 index 00000000..ce22700a --- /dev/null +++ b/oscurart_tools/files/collect_images.py @@ -0,0 +1,59 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8 compliant> + +import bpy +from bpy.types import Operator +import os +import shutil + + +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: + try: + image.update() + + if image.has_data: + 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: + print("%s exists." % (image.name)) + else: + print("%s missing path." % (image.name)) + except: + print("%s missing path." % (image.name)) + + bpy.ops.file.make_paths_relative() + + return {'FINISHED'} diff --git a/oscurart_tools/files/reload_images.py b/oscurart_tools/files/reload_images.py new file mode 100644 index 00000000..68b5c61b --- /dev/null +++ b/oscurart_tools/files/reload_images.py @@ -0,0 +1,37 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8 compliant> + +import bpy +from bpy.types import Operator + + + +class reloadImages (Operator): + """Reloads all bitmaps in the scene""" + bl_idname = "image.reload_images_osc" + bl_label = "Reload Images" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + for imgs in bpy.data.images: + imgs.reload() + return {'FINISHED'} + + diff --git a/oscurart_tools/files/save_incremental.py b/oscurart_tools/files/save_incremental.py new file mode 100644 index 00000000..d655b08e --- /dev/null +++ b/oscurart_tools/files/save_incremental.py @@ -0,0 +1,70 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8 compliant> + +import bpy +from bpy.types import Operator +import os + + +def saveBkp (self, context): + fileFolder = os.path.dirname(bpy.data.filepath) + versionFolder = os.path.join(fileFolder,"VERSIONS") + + #creo folder + if os.path.exists(versionFolder): + print("existe") + else: + os.mkdir(versionFolder) + + #sin version a versionada + if not bpy.data.filepath.count("_v"): + filelist = [file for file in os.listdir(versionFolder) if file.count("_v") and not file.count("blend1")] + + filelower = 0 + print(filelist) + for file in filelist: + if int(file.split(".")[0][-2:]) > filelower: + filelower = int(file.split(".")[0][-2:]) + + savepath = "%s/VERSIONS/%s_v%02d.blend" % (os.path.dirname(bpy.data.filepath),bpy.path.basename(bpy.data.filepath).split('.')[0],filelower+1) + print("Copia versionada guardada.") + bpy.ops.wm.save_as_mainfile() + bpy.ops.wm.save_as_mainfile(filepath=savepath, copy=True) + + else: + #versionada a sin version + if bpy.data.filepath.count("_v"): + filename = "%s/../%s.blend" % (os.path.dirname(bpy.data.filepath),os.path.basename(bpy.data.filepath).rpartition(".")[0].rpartition("_")[0]) + print(filename) + bpy.ops.wm.save_as_mainfile(filepath=filename, copy=True) + print("Copia sin version guardada.") + + +class saveIncrementalBackup (bpy.types.Operator): + """Save incremental backup in versions folder""" + bl_idname = "file.save_incremental_backup" + bl_label = "Save Incremental Backup" + bl_options = {'REGISTER', 'UNDO'} + + def execute(self, context): + saveBkp(self, context) + return {'FINISHED'} + + |