From a3ca868eb3946892d57f067e529d4b227a358119 Mon Sep 17 00:00:00 2001 From: Daniel Grauer Date: Tue, 1 Aug 2023 16:19:34 +0200 Subject: [PATCH 1/4] Fix: ensure loaded path is folder and not file The input path to load brush sets only works with a folder as path. If a file is selected in the filemanger to load the path the import fails and throws a error. To avoid the import failing, the filename is now stripped from the path to load the folder. --- io_import_BrushSet.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/io_import_BrushSet.py b/io_import_BrushSet.py index a67e2c52d..fbf550ae3 100644 --- a/io_import_BrushSet.py +++ b/io_import_BrushSet.py @@ -51,6 +51,12 @@ ext_list = ['.bmp', fakeUser = False def LoadBrushSet(filepath, filename): + + # Ensure filepath is a path and not a file (this can happen when the user selects a file within the folder) + if os.path.isfile(filepath): + path, file = os.path.split(filepath) + filepath = os.path.join(path + "\\") + for file in os.listdir(filepath): path = (filepath + file) -- 2.30.2 From 195acac65ecc5a3a36b6bc554ccf66fd9ae2f975 Mon Sep 17 00:00:00 2001 From: Daniel Grauer Date: Sat, 19 Aug 2023 23:26:53 +0200 Subject: [PATCH 2/4] replace filepath with directory to avoid workaround --- io_import_BrushSet.py | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/io_import_BrushSet.py b/io_import_BrushSet.py index fbf550ae3..70f27f5b6 100644 --- a/io_import_BrushSet.py +++ b/io_import_BrushSet.py @@ -50,18 +50,13 @@ ext_list = ['.bmp', fakeUser = False -def LoadBrushSet(filepath, filename): +def LoadBrushSet(directory): - # Ensure filepath is a path and not a file (this can happen when the user selects a file within the folder) - if os.path.isfile(filepath): - path, file = os.path.split(filepath) - filepath = os.path.join(path + "\\") - - for file in os.listdir(filepath): - path = (filepath + file) + for file in os.listdir(directory): + path = os.path.join(directory + file) # get folder name - (f1, f2) = os.path.split(filepath) + (f1, f2) = os.path.split(directory) (f3, foldername) = os.path.split(f1) # filter files by extensions (filter images) @@ -93,22 +88,11 @@ class BrushSetImporter(bpy.types.Operator): bl_idname = "import_image.brushset" bl_label = "Import BrushSet" - filename: StringProperty(name = "File Name", - description = "filepath", - default = "", - maxlen = 1024, - options = {'ANIMATABLE'}, - subtype = 'NONE') + directory: bpy.props.StringProperty(name="Directory", options={"HIDDEN"}) - filepath: StringProperty(name = "File Name", - description = "filepath", - default = "", - maxlen = 1024, - options = {'ANIMATABLE'}, - subtype = 'NONE') def execute(self, context): - LoadBrushSet(self.properties.filepath, self.properties.filename) + LoadBrushSet(self.directory) return {'FINISHED'} def invoke(self, context, event): -- 2.30.2 From 9bedba2ac51b795607a6b00a20cd0866fa885643 Mon Sep 17 00:00:00 2001 From: Daniel Grauer Date: Sat, 19 Aug 2023 23:27:45 +0200 Subject: [PATCH 3/4] add filtering to window manager to only show folders and images since this is what the user wants to see when using this addon --- io_import_BrushSet.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/io_import_BrushSet.py b/io_import_BrushSet.py index 70f27f5b6..576c9b6db 100644 --- a/io_import_BrushSet.py +++ b/io_import_BrushSet.py @@ -90,6 +90,13 @@ class BrushSetImporter(bpy.types.Operator): directory: bpy.props.StringProperty(name="Directory", options={"HIDDEN"}) + set_default_filters: bool = True + def draw(self, context): + if self.set_default_filters: + context.space_data.params.use_filter = True + context.space_data.params.use_filter_folder = True + context.space_data.params.use_filter_image = True + self.set_default_filters = False def execute(self, context): LoadBrushSet(self.directory) -- 2.30.2 From 1b985c5ed79bb8335f66f7a3af2cafdce01761e1 Mon Sep 17 00:00:00 2001 From: Daniel Grauer Date: Sun, 20 Aug 2023 15:19:32 +0200 Subject: [PATCH 4/4] optimize register/unregister --- io_import_BrushSet.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/io_import_BrushSet.py b/io_import_BrushSet.py index 576c9b6db..3efdd705e 100644 --- a/io_import_BrushSet.py +++ b/io_import_BrushSet.py @@ -13,7 +13,6 @@ #---------------------------------------------# import bpy import os -from bpy.props import * # addon description bl_info = { @@ -145,16 +144,14 @@ classes = ( def register(): - from bpy.utils import register_class for cls in classes: - register_class(cls) + bpy.utils.register_class(cls) bpy.types.TOPBAR_MT_file_import.append(menu_func) def unregister(): - from bpy.utils import unregister_class for cls in reversed(classes): - unregister_class(cls) + bpy.utils.unregister_class(cls) bpy.types.TOPBAR_MT_file_import.remove(menu_func) -- 2.30.2