3
3
import fileseq
4
4
from .messenger import *
5
5
import traceback
6
- from .utils import refresh_obj , show_message_box
6
+ from .utils import refresh_obj , show_message_box , get_relative_path
7
7
from .importer import create_obj , create_meshio_obj
8
8
import numpy as np
9
9
10
10
addon_name = "blendersequenceloader"
11
11
12
+ def relative_path_error ():
13
+ show_message_box ("When using relative path, please save file before using it" , icon = "ERROR" )
14
+ return {"CANCELLED" }
15
+
16
+ def get_transform_matrix (importer_prop ):
17
+ if importer_prop .use_custom_transform :
18
+ return Matrix .LocRotScale (importer_prop .custom_location , importer_prop .custom_rotation , importer_prop .custom_scale )
19
+ else :
20
+ return Matrix .Identity (4 )
21
+
22
+ def create_obj_wrapper (seq , importer_prop ):
23
+ create_obj (seq , importer_prop .use_relative , importer_prop .root_path , transform_matrix = get_transform_matrix (importer_prop ))
24
+
12
25
# Here are load and delete operations
13
26
class BSEQ_OT_load (bpy .types .Operator ):
14
27
'''This operator loads a sequence'''
@@ -20,10 +33,8 @@ def execute(self, context):
20
33
scene = context .scene
21
34
importer_prop = scene .BSEQ
22
35
23
- if importer_prop .relative and not bpy .data .is_saved :
24
- # use relative but file not saved
25
- show_message_box ("When using relative path, please save file before using it" , icon = "ERROR" )
26
- return {"CANCELLED" }
36
+ if importer_prop .use_relative and not bpy .data .is_saved :
37
+ return relative_path_error ()
27
38
28
39
fs = importer_prop .fileseq
29
40
use_pattern = importer_prop .use_pattern
@@ -43,13 +54,7 @@ def execute(self, context):
43
54
show_message_box (traceback .format_exc (), "Can't find sequence: " + str (fs ), "ERROR" )
44
55
return {"CANCELLED" }
45
56
46
- transform_matrix = (Matrix .LocRotScale (
47
- importer_prop .custom_location ,
48
- importer_prop .custom_rotation ,
49
- importer_prop .custom_scale )
50
- if importer_prop .use_custom_transform else Matrix .Identity (4 ))
51
-
52
- create_obj (fs , importer_prop .root_path , transform_matrix = transform_matrix )
57
+ create_obj_wrapper (fs , importer_prop )
53
58
return {"FINISHED" }
54
59
55
60
@@ -63,10 +68,9 @@ def execute(self, context):
63
68
scene = context .scene
64
69
importer_prop = scene .BSEQ
65
70
66
- if importer_prop .relative and not bpy .data .is_saved :
71
+ if importer_prop .use_relative and not bpy .data .is_saved :
67
72
# use relative but file not saved
68
- show_message_box ("When using relative path, please save file before using it" , icon = "ERROR" )
69
- return {"CANCELLED" }
73
+ return relative_path_error ()
70
74
71
75
fs = importer_prop .fileseq
72
76
use_pattern = importer_prop .use_pattern
@@ -93,7 +97,7 @@ def execute(self, context):
93
97
obj = sim_loader .edit_obj
94
98
if not obj :
95
99
return {"CANCELLED" }
96
- if importer_prop .relative :
100
+ if importer_prop .use_relative :
97
101
if importer_prop .root_path != "" :
98
102
object .BSEQ .pattern = bpy .path .relpath (str (fileseq ), start = importer_prop .root_path )
99
103
else :
@@ -379,10 +383,8 @@ def execute(self, context):
379
383
scene = context .scene
380
384
importer_prop = scene .BSEQ
381
385
382
- if importer_prop .relative and not bpy .data .is_saved :
383
- # use relative but file not saved
384
- show_message_box ("When using relative path, please save file before using it" , icon = "ERROR" )
385
- return {"CANCELLED" }
386
+ if importer_prop .use_relative and not bpy .data .is_saved :
387
+ return relative_path_error ()
386
388
387
389
self .filter_glob = '*'
388
390
@@ -393,13 +395,13 @@ def execute(self, context):
393
395
# Check if there exists a matching file sequence for every selection
394
396
fp = str (Path (folder .parent , selection .name ))
395
397
seqs = fileseq .findSequencesOnDisk (str (folder .parent ))
396
- matching_seqs = [s for s in seqs if fp in list (s ) and s not in used_seqs ]
397
-
398
- if matching_seqs :
399
- transform_matrix = ( Matrix . LocRotScale ( importer_prop . custom_location , importer_prop . custom_rotation , importer_prop . custom_scale )
400
- if importer_prop . use_custom_transform else Matrix . Identity ( 4 ))
401
- create_obj ( matching_seqs [ 0 ], importer_prop . root_path , transform_matrix = transform_matrix )
402
- used_seqs . add ( matching_seqs [ 0 ] )
398
+ matching_seq = [s for s in seqs if fp in list (s ) and str ( s ) not in used_seqs ]
399
+
400
+ if matching_seq :
401
+ matching_seq = matching_seq [ 0 ]
402
+ used_seqs . add ( str ( matching_seq ))
403
+
404
+ create_obj_wrapper ( matching_seq , importer_prop )
403
405
return {'FINISHED' }
404
406
405
407
def draw (self , context ):
@@ -425,15 +427,15 @@ def draw(self, context):
425
427
layout .use_property_split = True
426
428
layout .use_property_decorate = False # No animation.
427
429
428
- # sfile = context.space_data
429
- # operator = sfile.active_operator
430
+ # # sfile = context.space_data
431
+ # # operator = sfile.active_operator
430
432
431
- layout .prop (importer_prop , 'filter_string' )
433
+ # layout.prop(importer_prop, 'filter_string')
432
434
433
- layout .alignment = 'LEFT'
434
- layout .prop (importer_prop , "relative" , text = "Relative Path" )
435
- if importer_prop .relative :
436
- layout .prop (importer_prop , "root_path" , text = "Root Directory" )
435
+ # layout.alignment = 'LEFT'
436
+ # layout.prop(importer_prop, "relative", text="Relative Path")
437
+ # if importer_prop.use_relative :
438
+ # layout.prop(importer_prop, "root_path", text="Root Directory")
437
439
438
440
class BSEQ_addon_preferences (bpy .types .AddonPreferences ):
439
441
bl_idname = addon_name
@@ -444,9 +446,10 @@ class BSEQ_addon_preferences(bpy.types.AddonPreferences):
444
446
)
445
447
446
448
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" )
449
+ # layout = self.layout
450
+ # layout.label(text="Please set a folder to store the extracted zip files")
451
+ # layout.prop(self, "zips_folder", text="Zips Folder")
452
+ pass
450
453
451
454
zip_folder_name = '/tmp_zips'
452
455
@@ -465,6 +468,8 @@ class BSEQ_OT_import_zip(bpy.types.Operator, ImportHelper):
465
468
files : bpy .props .CollectionProperty (type = bpy .types .PropertyGroup )
466
469
467
470
def execute (self , context ):
471
+ importer_prop = context .scene .BSEQ
472
+
468
473
import zipfile
469
474
zip_file = zipfile .ZipFile (self .filepath )
470
475
@@ -477,14 +482,19 @@ def execute(self, context):
477
482
478
483
valid_files = [info .filename for info in zip_file .infolist () if not info .filename .startswith ('__MACOSX/' )]
479
484
zip_file .extractall (zips_folder , members = valid_files )
480
- zip_file .close ()
485
+ zip_file .close ()
481
486
482
487
folder = str (zips_folder ) + '/' + str (Path (self .filepath ).name )[:- 4 ]
483
488
print (folder )
484
489
485
490
seqs = fileseq .findSequencesOnDisk (str (folder ))
491
+ if not seqs :
492
+ show_message_box ("No sequences found in the zip file" , icon = "ERROR" )
493
+ return {"CANCELLED" }
494
+
486
495
for s in seqs :
487
- create_obj (s , folder , transform_matrix = Matrix .Identity (4 ))
496
+ # Import it with absolute paths
497
+ create_obj (s , False , folder , transform_matrix = get_transform_matrix (importer_prop ))
488
498
489
499
# created_folder = context.scene.BSEQ.imported_zips.add()
490
500
# created_folder.path = folder
@@ -509,6 +519,28 @@ def execute(self, context):
509
519
510
520
return {'FINISHED' }
511
521
522
+ class BSEQ_OT_load_all (bpy .types .Operator ):
523
+ """Load all sequences"""
524
+ bl_idname = "bseq.load_all"
525
+ bl_label = "Load All"
526
+ bl_options = {'PRESET' , 'UNDO' }
527
+
528
+ def execute (self , context ):
529
+ importer_prop = context .scene .BSEQ
530
+
531
+ if importer_prop .use_relative and not bpy .data .is_saved :
532
+ return relative_path_error ()
533
+
534
+ dir = importer_prop .path
535
+ seqs = fileseq .findSequencesOnDisk (str (dir ))
536
+
537
+ for s in seqs :
538
+ print (s )
539
+
540
+ for s in seqs :
541
+ create_obj_wrapper (s , importer_prop )
542
+ return {'FINISHED' }
543
+
512
544
513
545
class BSEQ_OT_meshio_object (bpy .types .Operator , ImportHelper ):
514
546
"""Batch Import Meshio Objects"""
0 commit comments