-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathin_gdtf.py
232 lines (193 loc) · 6.99 KB
/
in_gdtf.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import os
import shutil
import traceback
from threading import Timer
import bpy
from bpy_extras.io_utils import ImportHelper
if bpy.app.version >= (4, 2):
from bpy_extras.io_utils import poll_file_object_drop
import pygdtf
from bpy.props import (
BoolProperty,
CollectionProperty,
FloatVectorProperty,
IntProperty,
StringProperty,
)
from .gdtf import DMX_GDTF
from .i18n import DMX_Lang
from .panels import profiles as Profiles
from .util import create_unique_fixture_name
_ = DMX_Lang._
from .logging import DMX_Log
def createDMXcollection():
dmx = bpy.context.scene.dmx
if not dmx.collection:
bpy.context.scene.dmx.new()
class DMX_OT_Import_GDTF(bpy.types.Operator, ImportHelper):
"""Import GDTF"""
bl_idname = "dmx.import_gdtf_into_scene"
bl_label = "Import GDTF (.gdtf)"
bl_options = {"PRESET", "UNDO"}
filename_ext = ".gdtf"
filter_glob: StringProperty(default="*.gdtf", options={"HIDDEN"})
files: CollectionProperty(
type=bpy.types.OperatorFileListElement, options={"HIDDEN", "SKIP_SAVE"}
)
directory: StringProperty(subtype="DIR_PATH")
patch: BoolProperty(
name="Patch into the scene",
description="Patch fixture into the scene",
default=False,
)
universe: IntProperty(
name=_("Universe"), description=_("DMX Universe"), default=0, min=0, max=511
)
address: IntProperty(
name=_("Address"), description=_("DMX Address"), default=1, min=1, max=512
)
gel_color: FloatVectorProperty(
name=_("Gel Color"),
subtype="COLOR",
size=4,
min=0.0,
max=1.0,
default=(1.0, 1.0, 1.0, 1.0),
)
display_beams: BoolProperty(
name=_("Display beams"),
description=_("Display beam projection and cone"),
# update = onDisplayBeams,
default=True,
)
add_target: BoolProperty(
name=_("Add Target"),
description=_("Add target for beam to follow"),
# update = onAddTarget,
default=True,
)
increment_address: BoolProperty(
name=_("Increment DMX address"),
description=_("Increment DMX address"),
default=True,
)
increment_fixture_id: BoolProperty(
name=_("Increment Fixture ID"),
description=_("Increment Fixture ID if numeric"),
default=True,
)
fixture_id: StringProperty(
name=_("Fixture ID"),
description=_(
"The Fixture ID is an identifier of this fixture that can be used to activate / select them for programming."
),
default="",
)
units: IntProperty(
name=_("Units"),
description=_("How many units of this light to add"),
default=1,
min=1,
max=1024,
)
def draw(self, context):
dmx = context.scene.dmx
if not dmx.collection:
Timer(0.5, createDMXcollection, ()).start()
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
layout.prop(self, "patch")
box = layout.column().box()
box.enabled = self.patch
box.prop(self, "units")
box.prop(self, "universe")
box.prop(self, "address")
box.prop(self, "fixture_id")
box.prop(self, "gel_color")
box.prop(self, "display_beams")
box.prop(self, "add_target")
box.prop(self, "increment_address")
box.prop(self, "increment_fixture_id")
def execute(self, context):
dmx = bpy.context.scene.dmx
folder_path = dmx.get_addon_path()
folder_path = os.path.join(folder_path, "assets", "profiles")
dmx = context.scene.dmx
address = self.address
universe = self.universe
fixture_id = self.fixture_id
for file in self.files:
if not file.name:
continue
file_path = os.path.join(self.directory, file.name)
DMX_Log.log.info(f"Importing GDTF Profile: {file_path}")
try:
shutil.copy(file_path, folder_path)
except shutil.SameFileError:
DMX_Log.log.debug(
"Importing file which already existed in the profiles folder"
)
if self.patch:
try:
file_name = os.path.join(folder_path, file.name)
profile = pygdtf.FixtureType(file_name)
mode, channel_count = list(DMX_GDTF.getModes(file_name).items())[0]
for count in range(1, 1 + self.units):
new_name = f"{profile.name} {count}"
new_name = create_unique_fixture_name(new_name)
dmx.addFixture(
new_name,
file_name,
universe,
address,
mode,
self.gel_color,
self.display_beams,
self.add_target,
fixture_id=fixture_id,
)
fixture = dmx.fixtures[-1]
DMX_Log.log.debug(f"Added fixture {fixture}")
if not fixture:
continue
if self.increment_fixture_id:
if fixture_id.isnumeric():
fixture_id = str(int(fixture_id) + 1)
if self.increment_address:
if (address + len(fixture.channels)) > 512:
universe += 1
address = 1
dmx.ensureUniverseExists(universe)
else:
address += len(fixture.channels)
except Exception as e:
traceback.print_exception(e)
DMX_GDTF.getManufacturerList()
Profiles.DMX_Fixtures_Local_Profile.loadLocal()
return {"FINISHED"}
if bpy.app.version >= (4, 1):
class DMX_IO_FH_GDTF(bpy.types.FileHandler):
bl_idname = "IO_FH_gdtf"
bl_label = "GDTF"
bl_import_operator = "dmx.import_gdtf_into_scene"
bl_file_extensions = ".gdtf"
@classmethod
def poll_drop(cls, context):
if bpy.app.version >= (4, 2):
return poll_file_object_drop(context)
def menu_func_import(self, context):
self.layout.operator(
DMX_OT_Import_GDTF.bl_idname,
text="General Device Type Format (.gdtf) into BlenderDMX",
)
def register():
bpy.utils.register_class(DMX_OT_Import_GDTF)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
if bpy.app.version >= (4, 1):
bpy.utils.register_class(DMX_IO_FH_GDTF)
def unregister():
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
if bpy.app.version >= (4, 1):
bpy.utils.unregister_class(DMX_IO_FH_GDTF)
bpy.utils.unregister_class(DMX_OT_Import_GDTF)