Skip to content

Commit 62fcd62

Browse files
committed
Imported extracted zip folders are stored in tmp_zips in a custom location and this whole folder is then deleted
1 parent 739f61d commit 62fcd62

File tree

5 files changed

+59
-33
lines changed

5 files changed

+59
-33
lines changed

__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "Sequence Loader",
33
"description": "Loader for meshio supported mesh files/ simulation sequences",
44
"author": "Interactive Computer Graphics",
5-
"version": (0, 1, 6),
6-
"blender": (3, 4, 0),
5+
"version": (0, 2, 0),
6+
"blender": (3, 6, 0),
77
"warning": "",
88
"support": "COMMUNITY",
99
"category": "Import-Export",
@@ -55,7 +55,8 @@
5555
BSEQ_PT_batch_sequences_settings,
5656
BSEQ_OT_meshio_object,
5757
BSEQ_OT_import_zip,
58-
BSEQ_OT_delete_zips
58+
BSEQ_OT_delete_zips,
59+
BSEQ_addon_preferences
5960
]
6061

6162
def register():
@@ -77,7 +78,6 @@ def register():
7778
def unregister():
7879
for cls in classes:
7980
bpy.utils.unregister_class(cls)
80-
bpy.utils.unregister_class(BSEQ_ImportedZip)
8181
bpy.types.TEXT_MT_templates.remove(draw_template)
8282
del bpy.types.Scene.BSEQ
8383
del bpy.types.Object.BSEQ

bseq/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from bseq.utils import refresh_obj
2-
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, BSEQ_OT_refresh_sequences, BSEQ_OT_set_start_end_frames, BSEQ_OT_batch_sequences, BSEQ_PT_batch_sequences_settings, BSEQ_OT_meshio_object, BSEQ_OT_import_zip, BSEQ_OT_delete_zips
3-
from .properties import BSEQ_scene_property, BSEQ_obj_property, BSEQ_mesh_property, BSEQ_ImportedZip
2+
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, BSEQ_OT_refresh_sequences, BSEQ_OT_set_start_end_frames, BSEQ_OT_batch_sequences, BSEQ_PT_batch_sequences_settings, BSEQ_OT_meshio_object, BSEQ_OT_import_zip, BSEQ_OT_delete_zips, BSEQ_addon_preferences
3+
from .properties import BSEQ_scene_property, BSEQ_obj_property, BSEQ_mesh_property
44
from .panels import BSEQ_UL_Obj_List, BSEQ_List_Panel, BSEQ_Settings, BSEQ_PT_Import, BSEQ_PT_Import_Child1, BSEQ_PT_Import_Child2, BSEQ_Globals_Panel, BSEQ_Advanced_Panel, BSEQ_Templates, BSEQ_UL_Att_List, draw_template
55
from .messenger import subscribe_to_selected, unsubscribe_to_selected
66
import bpy
@@ -57,5 +57,5 @@ def BSEQ_initialize(scene):
5757
"BSEQ_OT_meshio_object",
5858
"BSEQ_OT_import_zip",
5959
"BSEQ_OT_delete_zips",
60-
"BSEQ_ImportedZip"
60+
"BSEQ_addon_preferences"
6161
]

bseq/operators.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from .importer import create_obj, create_meshio_obj
88
import numpy as np
99

10+
addon_name = "blendersequenceloader"
11+
1012
# Here are load and delete operations
1113
class BSEQ_OT_load(bpy.types.Operator):
1214
'''This operator loads a sequence'''
@@ -433,6 +435,21 @@ def draw(self, context):
433435
if importer_prop.relative:
434436
layout.prop(importer_prop, "root_path", text="Root Directory")
435437

438+
class BSEQ_addon_preferences(bpy.types.AddonPreferences):
439+
bl_idname = addon_name
440+
441+
zips_folder: bpy.props.StringProperty(
442+
name="Zips Folder",
443+
subtype='DIR_PATH',
444+
)
445+
446+
def draw(self, context):
447+
layout = self.layout
448+
layout.label(text="Please set a folder to store the extracted zip files")
449+
layout.prop(self, "zips_folder", text="Zips Folder")
450+
451+
zip_folder_name = '/tmp_zips'
452+
436453
class BSEQ_OT_import_zip(bpy.types.Operator, ImportHelper):
437454
"""Import a zip file"""
438455
bl_idname = "bseq.import_zip"
@@ -450,18 +467,27 @@ class BSEQ_OT_import_zip(bpy.types.Operator, ImportHelper):
450467
def execute(self, context):
451468
import zipfile
452469
zip_file = zipfile.ZipFile(self.filepath)
453-
zip_file.extractall(Path(self.filepath).parent)
470+
471+
addon_prefs = context.preferences.addons[addon_name].preferences
472+
# Check if a string is empty:
473+
if not addon_prefs.zips_folder:
474+
show_message_box("Please set a folder to store the extracted zip files", icon="ERROR")
475+
return {"CANCELLED"}
476+
zips_folder = addon_prefs.zips_folder + zip_folder_name
477+
478+
valid_files = [info.filename for info in zip_file.infolist() if not info.filename.startswith('__MACOSX/')]
479+
zip_file.extractall(zips_folder, members=valid_files)
454480
zip_file.close()
455481

456-
folder = str(Path(self.filepath).parent) + '/' + str(Path(self.filepath).name)
457-
folder = folder[:-4]
482+
folder = str(zips_folder) + '/' + str(Path(self.filepath).name)[:-4]
483+
print(folder)
458484

459485
seqs = fileseq.findSequencesOnDisk(str(folder))
460486
for s in seqs:
461487
create_obj(s, folder, transform_matrix=Matrix.Identity(4))
462488

463-
created_folder = context.scene.BSEQ.imported_zips.add()
464-
created_folder.path = folder
489+
# created_folder = context.scene.BSEQ.imported_zips.add()
490+
# created_folder.path = folder
465491

466492
return {'FINISHED'}
467493

@@ -472,10 +498,15 @@ class BSEQ_OT_delete_zips(bpy.types.Operator):
472498
bl_options = {'PRESET', 'UNDO'}
473499

474500
def execute(self, context):
475-
folders = context.scene.BSEQ.imported_zips
476-
for folder in folders:
477-
import shutil
478-
shutil.rmtree(folder.path)
501+
# folders = context.scene.BSEQ.imported_zips
502+
# for folder in folders:
503+
504+
addon_prefs = context.preferences.addons[addon_name].preferences
505+
zips_folder = addon_prefs.zips_folder + zip_folder_name
506+
507+
import shutil
508+
shutil.rmtree(zips_folder)
509+
479510
return {'FINISHED'}
480511

481512

bseq/panels.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ def draw(self, context):
207207
scene = context.scene
208208
importer_prop = scene.BSEQ
209209

210-
layout.operator("wm.seq_import_batch")
210+
row = layout.row()
211+
212+
row.scale_y = 1.5
213+
row.operator("wm.seq_import_batch")
211214

212215
split = layout.split()
213216
col1 = split.column()
@@ -249,13 +252,6 @@ def draw(self, context):
249252
box_col3.label(text="Scale:")
250253
box_col3.prop(importer_prop, "custom_scale", text="")
251254

252-
split = layout.split(factor=0.5)
253-
col1 = split.column()
254-
col2 = split.column()
255-
256-
col1.operator("bseq.import_zip", text="Import from zip")
257-
col2.operator("bseq.delete_zips", text="Delete created folders")
258-
259255
class BSEQ_PT_Import_Child1(BSEQ_Panel, bpy.types.Panel):
260256
bl_parent_id = "BSEQ_PT_panel"
261257
bl_label = "Import from folder"
@@ -288,6 +284,14 @@ def draw(self, context):
288284

289285
layout.operator("sequence.load")
290286

287+
split = layout.split(factor=0.5)
288+
col1 = split.column()
289+
col2 = split.column()
290+
291+
col1.operator("bseq.import_zip", text="Import from zip")
292+
col2.operator("bseq.delete_zips", text="Delete created folders")
293+
294+
291295
class BSEQ_PT_Import_Child2(BSEQ_Panel, bpy.types.Panel):
292296
bl_parent_id = "BSEQ_PT_panel"
293297
bl_label = "Test"

bseq/properties.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
from .callback import *
33
from mathutils import Matrix
44

5-
class BSEQ_ImportedZip(bpy.types.PropertyGroup):
6-
path: bpy.props.StringProperty(name="Directory",
7-
subtype="DIR_PATH",
8-
)
9-
10-
bpy.utils.register_class(BSEQ_ImportedZip)
11-
125
class BSEQ_scene_property(bpy.types.PropertyGroup):
136
path: bpy.props.StringProperty(name="Directory",
147
subtype="DIR_PATH",
@@ -120,8 +113,6 @@ class BSEQ_scene_property(bpy.types.PropertyGroup):
120113
default='',
121114
)
122115

123-
imported_zips: bpy.props.CollectionProperty(type=BSEQ_ImportedZip)
124-
125116
class BSEQ_obj_property(bpy.types.PropertyGroup):
126117
init: bpy.props.BoolProperty(default=False)
127118
enabled: bpy.props.BoolProperty(default=True,

0 commit comments

Comments
 (0)