Skip to content

Added Enable/Disable All and the option to select a root directory for relative paths #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
BSEQ_OT_disable_selected,
BSEQ_OT_enable_selected,
BSEQ_OT_refresh_seq,
BSEQ_OT_disable_all,
BSEQ_OT_enable_all,
]


Expand Down
4 changes: 3 additions & 1 deletion bseq/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
]
2 changes: 1 addition & 1 deletion bseq/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def auto_refresh(scene, depsgraph=None):
continue
if obj.mode != "OBJECT":
continue
refresh_obj(obj)
refresh_obj(obj, scene)
17 changes: 12 additions & 5 deletions bseq/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -156,9 +156,12 @@ 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:
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
Expand Down Expand Up @@ -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)
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)
Expand Down
28 changes: 26 additions & 2 deletions bseq/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down Expand Up @@ -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"}
8 changes: 8 additions & 0 deletions bseq/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions bseq/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions bseq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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