-
Notifications
You must be signed in to change notification settings - Fork 1
/
operator_wav_import.py
58 lines (42 loc) · 1.51 KB
/
operator_wav_import.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import bpy
import os
def import_wav_files(filepath, pack, dir, fake):
def import_one(fp):
sound = bpy.data.sounds.load(fp, check_existing=False)
if pack:
sound.pack()
if fake:
sound.use_fake_user = True
if dir:
the_dir = os.path.dirname(filepath)
for child in os.listdir(the_dir):
if child.endswith(".wav"):
import_one(os.path.join(the_dir, child))
else:
import_one(filepath)
return {'FINISHED'}
from bpy_extras.io_utils import ImportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
class ImportWav(Operator, ImportHelper):
"""Import WAV audio files"""
bl_idname = "import_test.wav_file_batch"
bl_label = "Import WAV Files"
filename_ext = ".wav"
filter_glob: StringProperty(
default="*.wav",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
fake: BoolProperty(
name="Add Fake User",
description="Add the Fake User to each of the sound files",
default=True,
)
all_in_directory: BoolProperty(
name="All Files in Folder",
description="Import every WAV file found in the folder as the selected file",
default=False,
)
def execute(self, _):
return import_wav_files(filepath=self.filepath, pack=False, dir=self.all_in_directory, fake=self.fake)