From b25a619b3bb84b3a0474c8d578be13ff5d963751 Mon Sep 17 00:00:00 2001 From: Julius Stotz Date: Wed, 7 Dec 2022 15:54:36 +0100 Subject: [PATCH 1/2] Added Enable/Disable All and the option to select a root directory for relative paths --- __init__.py | 2 ++ bseq/__init__.py | 4 +++- bseq/globals.py | 2 +- bseq/importer.py | 10 +++++----- bseq/operators.py | 28 ++++++++++++++++++++++++++-- bseq/panels.py | 8 ++++++++ bseq/properties.py | 4 ++++ bseq/utils.py | 6 +++--- 8 files changed, 52 insertions(+), 12 deletions(-) diff --git a/__init__.py b/__init__.py index 2f08102..9e0eaa8 100644 --- a/__init__.py +++ b/__init__.py @@ -42,6 +42,8 @@ BSEQ_OT_disable_selected, BSEQ_OT_enable_selected, BSEQ_OT_refresh_seq, + BSEQ_OT_disable_all, + BSEQ_OT_enable_all, ] diff --git a/bseq/__init__.py b/bseq/__init__.py index edaf58c..7740e59 100644 --- a/bseq/__init__.py +++ b/bseq/__init__.py @@ -1,5 +1,5 @@ from bseq.utils import refresh_obj -from .operators import BSEQ_OT_load, BSEQ_OT_edit, BSEQ_OT_resetpt, BSEQ_OT_resetmesh, BSEQ_OT_resetins, BSEQ_OT_set_as_split_norm, BSEQ_OT_remove_split_norm, BSEQ_OT_disable_selected, BSEQ_OT_enable_selected, BSEQ_OT_refresh_seq +from .operators import BSEQ_OT_load, BSEQ_OT_edit, BSEQ_OT_resetpt, BSEQ_OT_resetmesh, BSEQ_OT_resetins, BSEQ_OT_set_as_split_norm, BSEQ_OT_remove_split_norm, BSEQ_OT_disable_selected, BSEQ_OT_enable_selected, BSEQ_OT_refresh_seq, BSEQ_OT_disable_all, BSEQ_OT_enable_all from .properties import BSEQ_scene_property, BSEQ_obj_property, BSEQ_mesh_property from .panels import BSEQ_UL_Obj_List, BSEQ_List_Panel, BSEQ_Settings, BSEQ_Import, BSEQ_Templates, BSEQ_UL_Att_List, draw_template from .messenger import subscribe_to_selected, unsubscribe_to_selected @@ -43,4 +43,6 @@ def BSEQ_initialize(scene): "BSEQ_OT_disable_selected", "BSEQ_OT_enable_selected", "BSEQ_OT_refresh_seq", + "BSEQ_OT_disable_all", + "BSEQ_OT_enable_all", ] diff --git a/bseq/globals.py b/bseq/globals.py index 5577a71..e875ff0 100644 --- a/bseq/globals.py +++ b/bseq/globals.py @@ -38,4 +38,4 @@ def auto_refresh(scene, depsgraph=None): continue if obj.mode != "OBJECT": continue - refresh_obj(obj) \ No newline at end of file + refresh_obj(obj, scene) \ No newline at end of file diff --git a/bseq/importer.py b/bseq/importer.py index 55c0079..a245542 100644 --- a/bseq/importer.py +++ b/bseq/importer.py @@ -137,7 +137,7 @@ def update_mesh(meshio_mesh, mesh): mesh.normals_split_custom_set_from_vertices(v) -def create_obj(fileseq, use_relaitve, transform_matrix=Matrix([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])): +def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])): current_frame = bpy.context.scene.frame_current filepath = fileseq[current_frame % len(fileseq)] @@ -156,9 +156,9 @@ def create_obj(fileseq, use_relaitve, transform_matrix=Matrix([[1, 0, 0, 0], [0, name = fileseq.basename() + "@" + fileseq.extension() mesh = bpy.data.meshes.new(name) object = bpy.data.objects.new(name, mesh) - object.BSEQ.use_relative = use_relaitve - if use_relaitve: - object.BSEQ.pattern = bpy.path.relpath(str(fileseq)) + object.BSEQ.use_relative = use_relative + if use_relative: + object.BSEQ.pattern = bpy.path.relpath(str(fileseq), start=root_path) else: object.BSEQ.pattern = str(fileseq) object.BSEQ.init = True @@ -191,7 +191,7 @@ def update_obj(scene, depsgraph=None): meshio_mesh = None pattern = obj.BSEQ.pattern if obj.BSEQ.use_relative: - pattern = bpy.path.abspath(pattern) + pattern = bpy.path.abspath(pattern, start=scene.BSEQ.root_path) # in case the blender file was created on windows system, but opened in linux system pattern = bpy.path.native_pathsep(pattern) fs = fileseq.FileSequence(pattern) diff --git a/bseq/operators.py b/bseq/operators.py index 05592d1..a469aba 100644 --- a/bseq/operators.py +++ b/bseq/operators.py @@ -41,7 +41,7 @@ def execute(self, context): show_message_box(traceback.format_exc(), "Can't find sequence: " + str(fs), "ERROR") return {"CANCELLED"} - create_obj(fs, importer_prop.relative) + create_obj(fs, importer_prop.relative, importer_prop.root_path) return {"FINISHED"} @@ -270,6 +270,30 @@ class BSEQ_OT_refresh_seq(bpy.types.Operator): def execute(self, context): scene = context.scene obj = bpy.data.objects[scene.BSEQ.selected_obj_num] - refresh_obj(obj) + refresh_obj(obj, scene) return {"FINISHED"} + +class BSEQ_OT_disable_all(bpy.types.Operator): + '''This operator disable all selected sequence''' + bl_label = "Disable All Sequences" + bl_idname = "bseq.disableall" + bl_options = {"UNDO"} + + def execute(self, context): + for obj in bpy.context.scene.collection.all_objects: + if obj.BSEQ.init and obj.BSEQ.enabled: + obj.BSEQ.enabled = False + return {"FINISHED"} + +class BSEQ_OT_enable_all(bpy.types.Operator): + '''This operator enable all selected sequence''' + bl_label = "Enable All Sequences" + bl_idname = "bseq.enableall" + bl_options = {"UNDO"} + + def execute(self, context): + for obj in bpy.context.scene.collection.all_objects: + if obj.BSEQ.init and not obj.BSEQ.enabled: + obj.BSEQ.enabled = True + return {"FINISHED"} diff --git a/bseq/panels.py b/bseq/panels.py index 4ef50e5..43d4f82 100644 --- a/bseq/panels.py +++ b/bseq/panels.py @@ -74,6 +74,10 @@ def draw(self, context): row.operator("bseq.enableselected", text="Enable Selected") row.operator("bseq.disableselected", text="Disable Selected") row.operator("bseq.refresh", text="Refresh") + row = layout.row() + row.operator("bseq.enableall", text="Enable All") + row.operator("bseq.disableall", text="Disable All") + class BSEQ_Settings(bpy.types.Panel): @@ -192,6 +196,10 @@ def draw(self, context): col1.label(text="Use Relative Path") col2.prop(importer_prop, "relative", text="") + if importer_prop.relative is True: + col1.label(text="Root Directory") + col2.prop(importer_prop, "root_path", text="") + layout.operator("sequence.load") split = layout.split() col1 = split.column() diff --git a/bseq/properties.py b/bseq/properties.py index 73e1ded..ed79cdb 100644 --- a/bseq/properties.py +++ b/bseq/properties.py @@ -8,6 +8,10 @@ class BSEQ_scene_property(bpy.types.PropertyGroup): description="You need to go to the folder with the sequence, then click \"Accept\". ", update=update_path) relative: bpy.props.BoolProperty(name='Use relative path', description="whether or not to use reletive path", default=False) + root_path: bpy.props.StringProperty(name="Root Directory", + subtype="DIR_PATH", + description="Select a root folder for all relative paths. When not set the current filename is used.", + update=update_path) fileseq: bpy.props.EnumProperty( name="File Sequences", description="Please choose the file sequences you want", diff --git a/bseq/utils.py b/bseq/utils.py index 775ee6b..af686b6 100644 --- a/bseq/utils.py +++ b/bseq/utils.py @@ -26,13 +26,13 @@ def stop_animation(): -def refresh_obj(obj): +def refresh_obj(obj, scene): fs = obj.BSEQ.pattern if obj.BSEQ.use_relative: - fs = bpy.path.abspath(fs) + fs = bpy.path.abspath(fs, start=scene.BSEQ.root_path) fs = fileseq.findSequenceOnDisk(fs) fs = fileseq.findSequenceOnDisk(fs.dirname() + fs.basename() + "@" + fs.extension()) fs = str(fs) if obj.BSEQ.use_relative: - fs = bpy.path.relpath(fs) + fs = bpy.path.relpath(fs, start=scene.BSEQ.root_path) obj.BSEQ.pattern = fs \ No newline at end of file From bb7131bfe23b8261608e4635981dd8af65e89eb6 Mon Sep 17 00:00:00 2001 From: Stefan Jeske Date: Wed, 22 Mar 2023 13:22:37 +0100 Subject: [PATCH 2/2] Keep previous default relative behavior when root is not set. --- bseq/importer.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bseq/importer.py b/bseq/importer.py index a245542..1897ec4 100644 --- a/bseq/importer.py +++ b/bseq/importer.py @@ -158,7 +158,10 @@ def create_obj(fileseq, use_relative, root_path, transform_matrix=Matrix([[1, 0, object = bpy.data.objects.new(name, mesh) object.BSEQ.use_relative = use_relative if use_relative: - object.BSEQ.pattern = bpy.path.relpath(str(fileseq), start=root_path) + if root_path != "": + object.BSEQ.pattern = bpy.path.relpath(str(fileseq), start=root_path) + else: + object.BSEQ.pattern = bpy.path.relpath(str(fileseq)) else: object.BSEQ.pattern = str(fileseq) object.BSEQ.init = True @@ -191,7 +194,11 @@ def update_obj(scene, depsgraph=None): meshio_mesh = None pattern = obj.BSEQ.pattern if obj.BSEQ.use_relative: - pattern = bpy.path.abspath(pattern, start=scene.BSEQ.root_path) + if scene.BSEQ.root_path != "": + pattern = bpy.path.abspath(pattern, start=scene.BSEQ.root_path) + else: + pattern = bpy.path.abspath(pattern) + # in case the blender file was created on windows system, but opened in linux system pattern = bpy.path.native_pathsep(pattern) fs = fileseq.FileSequence(pattern)