diff options
Diffstat (limited to 'archipack/archipack_rendering.py')
-rw-r--r-- | archipack/archipack_rendering.py | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/archipack/archipack_rendering.py b/archipack/archipack_rendering.py index 05373a75..fced24ac 100644 --- a/archipack/archipack_rendering.py +++ b/archipack/archipack_rendering.py @@ -30,6 +30,7 @@ import bpy # noinspection PyUnresolvedReferences import bgl +from shutil import copyfile from os import path, remove, listdir from sys import exc_info import subprocess @@ -38,14 +39,21 @@ import bpy_extras.image_utils as img_utils # noinspection PyUnresolvedReferences from math import ceil from bpy.types import Operator +from bl_ui import properties_render class ARCHIPACK_OT_render_thumbs(Operator): bl_idname = "archipack.render_thumbs" - bl_label = "Render preset thumbs" - bl_description = "Render all presets thumbs" + bl_label = "Render presets thumbs" + bl_description = "Setup default presets and update thumbs" bl_options = {'REGISTER', 'INTERNAL'} + @classmethod + def poll(cls, context): + # Ensure CYCLES engine is available + return context.scene.archipack_progress < 0 and \ + 'CYCLES' in properties_render.RENDER_PT_render.COMPAT_ENGINES + def background_render(self, context, cls, preset): generator = path.dirname(path.realpath(__file__)) + path.sep + "archipack_thumbs.py" addon_name = __name__.split('.')[0] @@ -63,24 +71,61 @@ class ARCHIPACK_OT_render_thumbs(Operator): "cls:" + cls, "preset:" + preset ] - popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) for stdout_line in iter(popen.stdout.readline, ""): yield stdout_line popen.stdout.close() popen.wait() - def scan_files(self, category): + def copy_to_user_path(self, category): + """ + Copy factory presets to writeable presets folder + Two cases here: + 1 there is not presets thumbs found (official version) + 2 thumbs allready are there (unofficial) + """ file_list = [] # load default presets dir_path = path.dirname(path.realpath(__file__)) sub_path = "presets" + path.sep + category - presets_path = path.join(dir_path, sub_path) - if path.exists(presets_path): - file_list += [presets_path + path.sep + f[:-3] - for f in listdir(presets_path) - if f.endswith('.py') and - not f.startswith('.')] + source_path = path.join(dir_path, sub_path) + if path.exists(source_path): + file_list.extend([f + for f in listdir(source_path) + if (f.endswith('.py') or f.endswith('.txt')) and + not f.startswith('.')]) + + target_path = path.join("presets", category) + presets_path = bpy.utils.user_resource('SCRIPTS', + target_path, + create=True) + # files from factory not found in user dosent require a recompute + skipfiles = [] + for f in file_list: + # copy python/txt preset + if not path.exists(presets_path + path.sep + f): + copyfile(source_path + path.sep + f, presets_path + path.sep + f) + + # skip txt files (material presets) + if f.endswith(".txt"): + skipfiles.append(f) + + # when thumbs allready are in factory folder but not found in user one + # simply copy them, and add preset to skip list + thumb_filename = f[:-3] + ".png" + if path.exists(source_path + path.sep + thumb_filename): + if not path.exists(presets_path + path.sep + thumb_filename): + copyfile(source_path + path.sep + thumb_filename, presets_path + path.sep + thumb_filename) + skipfiles.append(f) + + return skipfiles + + def scan_files(self, category): + file_list = [] + + # copy from factory to user writeable folder + skipfiles = self.copy_to_user_path(category) + # load user def presets preset_paths = bpy.utils.script_paths("presets") for preset in preset_paths: @@ -89,7 +134,8 @@ class ARCHIPACK_OT_render_thumbs(Operator): file_list += [presets_path + path.sep + f[:-3] for f in listdir(presets_path) if f.endswith('.py') and - not f.startswith('.')] + not f.startswith('.') and + f not in skipfiles] file_list.sort() return file_list @@ -99,7 +145,7 @@ class ARCHIPACK_OT_render_thumbs(Operator): dir_path = path.dirname(path.realpath(__file__)) sub_path = "presets" presets_path = path.join(dir_path, sub_path) - print(presets_path) + # print(presets_path) if path.exists(presets_path): dirs = listdir(presets_path) for dir in dirs: @@ -119,11 +165,12 @@ class ARCHIPACK_OT_render_thumbs(Operator): # elif not "Fra:1" in l: # print(l.strip()) - @classmethod - def poll(cls, context): - return context.scene.archipack_progress < 0 - def invoke(self, context, event): + addon_name = __name__.split('.')[0] + matlib_path = context.user_preferences.addons[addon_name].preferences.matlib_path + + if matlib_path == '': + self.report({'WARNING'}, "You should setup a default material library path in addon preferences") return context.window_manager.invoke_confirm(self, event) def execute(self, context): |