From 9aebb6cb001fcb63c491989c6ef158baaeff2808 Mon Sep 17 00:00:00 2001 From: Spiderguy-F Date: Thu, 15 Feb 2024 14:04:51 +0100 Subject: [PATCH 1/3] Fix Open Image Relative Path failing --- addons/io_hubs_addon/components/operators.py | 29 ++++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/addons/io_hubs_addon/components/operators.py b/addons/io_hubs_addon/components/operators.py index b2b79ee6..048c8554 100644 --- a/addons/io_hubs_addon/components/operators.py +++ b/addons/io_hubs_addon/components/operators.py @@ -606,11 +606,12 @@ class OpenImage(Operator): bl_label = "Open Image" bl_options = {'REGISTER', 'UNDO'} + directory: StringProperty() filepath: StringProperty(subtype="FILE_PATH") files: CollectionProperty(type=PropertyGroup) filter_folder: BoolProperty(default=True, options={"HIDDEN"}) filter_image: BoolProperty(default=True, options={"HIDDEN"}) - target_property: StringProperty() + target_property: StringProperty(options={"HIDDEN"}) relative_path: BoolProperty( name="Relative Path", description="Select the file relative to the blend file", default=True) @@ -634,38 +635,42 @@ def poll(cls, context): return False return True - - def draw(self, context): - layout = self.layout + + def draw(self, context): #this def is obsolete, bc. target_property is hidden by default now and relative_path is displayed by default anyways + layout = self.layout layout.prop(self, "relative_path") - + def execute(self, context): - dirname = os.path.dirname(self.filepath) - + #dirname = os.path.dirname(self.filepath) #dirname fails if path selected in the Blender File View is relative (starts with //) on Windows + print("filepath:", self.filepath) if not self.files[0].name: - self.report({'INFO'}, "Open image cancelled. No image selected.") + self.report({'INFO'}, "Open image cancelled. No image selected.") return {'CANCELLED'} old_img = getattr(self.target, self.target_property) # Load/Reload the first image and assign it to the target property, then load the rest of the images if they're not already loaded. This mimics Blender's default open files behavior. - primary_filepath = os.path.join(dirname, self.files[0].name) + primary_filepath = os.path.join(self.directory, self.files[0].name) #self.files is sorted alphabetically by Blender, self.files[0] is the 1. of the selection in alphabetical order primary_img = bpy.data.images.load( filepath=primary_filepath, check_existing=True) primary_img.reload() setattr(self.target, self.target_property, primary_img) for f in self.files[1:]: - bpy.data.images.load(filepath=os.path.join( - dirname, f.name), check_existing=True) + bpy.data.images.load(filepath=os.path.join( #join works with both relative and absolute paths + self.directory, f.name), check_existing=True) update_image_editors(old_img, primary_img) redraw_component_ui(context) return {'FINISHED'} def invoke(self, context, event): - self.filepath = "" self.target = context.target + + last_image = getattr(self.target, self.target_property) + if type(last_image) == bpy.types.Image: #if the component has been assigned before, get its filepath + self.filepath = last_image.filepath #start the file browser at the location of the previous file + context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} From f4166b692824658f7790fcb03bb3dc9816ef7b60 Mon Sep 17 00:00:00 2001 From: Spiderguy-F Date: Thu, 15 Feb 2024 16:33:35 +0100 Subject: [PATCH 2/3] Removed Printout --- addons/io_hubs_addon/components/operators.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/io_hubs_addon/components/operators.py b/addons/io_hubs_addon/components/operators.py index 048c8554..dd3bab4b 100644 --- a/addons/io_hubs_addon/components/operators.py +++ b/addons/io_hubs_addon/components/operators.py @@ -642,7 +642,6 @@ def draw(self, context): #this def is obsolete, bc. target_property is hidden by def execute(self, context): #dirname = os.path.dirname(self.filepath) #dirname fails if path selected in the Blender File View is relative (starts with //) on Windows - print("filepath:", self.filepath) if not self.files[0].name: self.report({'INFO'}, "Open image cancelled. No image selected.") return {'CANCELLED'} From 3568f5e84314aae2e1ba14526a8eedc44f3a26c7 Mon Sep 17 00:00:00 2001 From: Spiderguy-F Date: Thu, 14 Mar 2024 12:22:40 +0100 Subject: [PATCH 3/3] Cosmetics Fixes --- addons/io_hubs_addon/components/operators.py | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/addons/io_hubs_addon/components/operators.py b/addons/io_hubs_addon/components/operators.py index dd3bab4b..7fa9ca29 100644 --- a/addons/io_hubs_addon/components/operators.py +++ b/addons/io_hubs_addon/components/operators.py @@ -509,7 +509,7 @@ def invoke(self, context, event): def split_and_prefix_report_messages(report_string): - return [f"{i+1:02d} {message}" for i, message in enumerate(report_string.split("\n\n"))] + return [f"{i + 1:02d} {message}" for i, message in enumerate(report_string.split("\n\n"))] class CopyHubsComponent(Operator): @@ -635,13 +635,8 @@ def poll(cls, context): return False return True - - def draw(self, context): #this def is obsolete, bc. target_property is hidden by default now and relative_path is displayed by default anyways - layout = self.layout - layout.prop(self, "relative_path") - + def execute(self, context): - #dirname = os.path.dirname(self.filepath) #dirname fails if path selected in the Blender File View is relative (starts with //) on Windows if not self.files[0].name: self.report({'INFO'}, "Open image cancelled. No image selected.") return {'CANCELLED'} @@ -649,14 +644,14 @@ def execute(self, context): old_img = getattr(self.target, self.target_property) # Load/Reload the first image and assign it to the target property, then load the rest of the images if they're not already loaded. This mimics Blender's default open files behavior. - primary_filepath = os.path.join(self.directory, self.files[0].name) #self.files is sorted alphabetically by Blender, self.files[0] is the 1. of the selection in alphabetical order + primary_filepath = os.path.join(self.directory, self.files[0].name) # self.files is sorted alphabetically by Blender, self.files[0] is the 1. of the selection in alphabetical order primary_img = bpy.data.images.load( filepath=primary_filepath, check_existing=True) primary_img.reload() setattr(self.target, self.target_property, primary_img) for f in self.files[1:]: - bpy.data.images.load(filepath=os.path.join( #join works with both relative and absolute paths + bpy.data.images.load(filepath=os.path.join( self.directory, f.name), check_existing=True) update_image_editors(old_img, primary_img) @@ -665,11 +660,11 @@ def execute(self, context): def invoke(self, context, event): self.target = context.target - + last_image = getattr(self.target, self.target_property) - if type(last_image) == bpy.types.Image: #if the component has been assigned before, get its filepath - self.filepath = last_image.filepath #start the file browser at the location of the previous file - + if type(last_image) is bpy.types.Image: # if the component has been assigned before, get its filepath + self.filepath = last_image.filepath # start the file browser at the location of the previous file + context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'}