Skip to content

Commit a2e1fad

Browse files
committed
Add 3D device label
1 parent c66473a commit a2e1fad

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

dmx.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ def register():
318318
for cls in DMX.classes_setup:
319319
bpy.utils.register_class(cls)
320320

321-
# register key shortcuts
322321
wm = bpy.context.window_manager
323322
km = wm.keyconfigs.addon.keymaps.new(
324323
name="3D View Generic", space_type="VIEW_3D"
@@ -1006,6 +1005,8 @@ def onDisplayLabel(self, context):
10061005
else:
10071006
if self.display_device_label == "NONE":
10081007
obj.show_name = False
1008+
elif self.display_device_label == "3D_LABEL":
1009+
obj.show_name = False
10091010
elif self.display_device_label == "NAME":
10101011
obj.name = f"{fixture_.user_fixture_name}"
10111012
obj.show_name = self.enable_device_label
@@ -1024,6 +1025,19 @@ def onDisplayLabel(self, context):
10241025
)
10251026
obj.show_name = self.enable_device_label
10261027

1028+
if obj.get("text_label", False):
1029+
obj.data.body = (
1030+
f"{fixture_.user_fixture_name} {fixture_.fixture_id or ''}"
1031+
)
1032+
if self.display_device_label == "3D_LABEL":
1033+
obj.hide_set(False)
1034+
obj.hide_viewport = False
1035+
obj.hide_render = False
1036+
else:
1037+
obj.hide_set(True)
1038+
obj.hide_viewport = True
1039+
obj.hide_render = True
1040+
10271041
def onDisplayPigtails(self, context):
10281042
for fixture_ in self.fixtures:
10291043
for obj in fixture_.collection.objects:
@@ -1061,7 +1075,21 @@ def onDisplay2D(self, context):
10611075
if self.display_2D:
10621076
obj.name = "geometry root"
10631077
obj.show_name = False
1064-
if obj.get("2d_symbol", None) == "all":
1078+
1079+
if obj.get("text_label", False):
1080+
obj.data.body = (
1081+
f"{fixture_.user_fixture_name} {fixture_.fixture_id or ''}"
1082+
)
1083+
if self.display_device_label == "3D_LABEL":
1084+
obj.hide_set(False)
1085+
obj.hide_viewport = False
1086+
obj.hide_render = False
1087+
else:
1088+
obj.hide_set(True)
1089+
obj.hide_viewport = True
1090+
obj.hide_render = True
1091+
1092+
elif obj.get("2d_symbol", None) == "all":
10651093
obj.hide_set(not self.display_2D)
10661094
obj.hide_viewport = not self.display_2D
10671095
obj.hide_render = not self.display_2D
@@ -1072,6 +1100,8 @@ def onDisplay2D(self, context):
10721100
else:
10731101
if self.display_device_label == "NONE":
10741102
obj.show_name = False
1103+
if self.display_device_label == "3D_LABEL":
1104+
obj.show_name = False
10751105
elif self.display_device_label == "NAME":
10761106
obj.name = f"{fixture_.user_fixture_name}"
10771107
obj.show_name = True
@@ -1085,10 +1115,9 @@ def onDisplay2D(self, context):
10851115
else:
10861116
obj.show_name = False
10871117
elif self.display_device_label == "FIXTURE_NAME_ID":
1088-
obj.name = (
1089-
f"{fixture_.user_fixture_name} {fixture_.fixture_id}"
1090-
)
1118+
obj.name = f"{fixture_.user_fixture_name} {fixture_.fixture_id or ''}"
10911119
obj.show_name = True
1120+
10921121
else:
10931122
obj.hide_set(self.display_2D)
10941123
obj.hide_viewport = self.display_2D
@@ -1130,6 +1159,7 @@ def update_device_label(self, context):
11301159
("DMX", _("DMX"), "DMX Address"),
11311160
("FIXTURE_ID", _("Fixture ID"), "Fixture ID"),
11321161
("FIXTURE_NAME_ID", _("Fixture Name + ID"), "Fixture Name + ID"),
1162+
("3D_LABEL", _("3D Fixture Name + ID"), "3D Fixture Name + ID"),
11331163
],
11341164
update = update_device_label)
11351165

fixture.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ def build(
756756
elif obj.get("2d_symbol", None) == "all":
757757
self.objects.add().name = "2D Symbol"
758758
self.objects["2D Symbol"].object = links[obj.name]
759+
elif obj.get("text_label", None) == "text_label":
760+
self.objects.add().name = "Text Label"
761+
self.objects["Text Label"].object = links[obj.name]
759762

760763
# Link all other object to collection
761764
self.collection.objects.link(links[obj.name])
@@ -879,6 +882,11 @@ def build(
879882
obj.hide_viewport = not bpy.context.scene.dmx.display_2D # keyframing
880883
obj.hide_render = not bpy.context.scene.dmx.display_2D
881884
continue
885+
if obj.get("text_label", None) == "text_label":
886+
obj.hide_set(not bpy.context.scene.dmx.display_2D)
887+
obj.hide_viewport = not bpy.context.scene.dmx.display_2D # keyframing
888+
obj.hide_render = not bpy.context.scene.dmx.display_2D
889+
continue
882890

883891
obj.hide_select = not bpy.context.scene.dmx.select_geometries
884892

@@ -2433,6 +2441,8 @@ def select(self, select_target=False):
24332441
obj.hide_render = not bpy.context.scene.dmx.display_pigtails
24342442
if obj.get("2d_symbol", None):
24352443
continue
2444+
if obj.get("text_label", None):
2445+
continue
24362446
obj.hide_set(False)
24372447
obj.hide_viewport = False # keyframing
24382448
obj.hide_render = False
@@ -2505,6 +2515,8 @@ def unselect(self):
25052515
for obj in self.collection.objects:
25062516
if obj.get("2d_symbol", None):
25072517
continue
2518+
if obj.get("text_label", None):
2519+
continue
25082520
obj.hide_set(True)
25092521
obj.hide_viewport = True # need for keyframing
25102522
obj.hide_render = True

gdtf.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,29 @@ def get_axis(attribute):
888888
constraint_copyRotation.use_x = False
889889
constraint_copyRotation.use_y = False
890890

891+
# Text object for label:
892+
893+
# bpy.ops.object.text_add( enter_editmode=False, align="WORLD", location=(0, 0, 0), scale=(1, 1, 1))
894+
bpy.ops.object.text_add()
895+
896+
obj = bpy.context.view_layer.objects.selected[0]
897+
898+
if obj is not None:
899+
obj.users_collection[0].objects.unlink(obj)
900+
obj["text_label"] = "text_label"
901+
objs["text_label"] = obj
902+
obj.show_in_front = True
903+
text_data = obj.data
904+
text_data.size = 0.08
905+
906+
constraint_copyLocation = obj.constraints.new(type="COPY_LOCATION")
907+
constraint_copyRotation = obj.constraints.new(type="COPY_ROTATION")
908+
constraint_copyLocation.target = base
909+
constraint_copyRotation.target = base
910+
constraint_copyRotation.use_z = True
911+
constraint_copyRotation.use_x = False
912+
constraint_copyRotation.use_y = False
913+
891914
# Link objects to collection
892915
for name, obj in objs.items():
893916
collection.objects.link(obj)

0 commit comments

Comments
 (0)