Skip to content

Commit cccb0fb

Browse files
committed
Store connections for round-tripping
1 parent 8bf898e commit cccb0fb

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

fixture.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from types import SimpleNamespace
2222
import uuid as py_uuid
2323
from itertools import zip_longest
24+
from xml.etree import ElementTree
2425

2526
import bpy
2627
import mathutils
@@ -515,6 +516,12 @@ def on_use_target(self, context):
515516
default = ""
516517
)
517518

519+
mvr_connections_xml: StringProperty(
520+
name = "MVR Connections XML",
521+
description = "Raw MVR <Connections> XML for round-tripping",
522+
default = ""
523+
)
524+
518525
dmx_breaks: CollectionProperty(
519526
name = "DMX Break",
520527
type = DMX_Break)
@@ -2785,6 +2792,20 @@ def to_mvr_fixture(self, universe_add=False):
27852792
for index, dmx_break in enumerate(self.dmx_breaks)
27862793
]
27872794

2795+
connections = None
2796+
connections_xml = (self.mvr_connections_xml or "").strip()
2797+
if connections_xml:
2798+
try:
2799+
connections_node = ElementTree.fromstring(connections_xml)
2800+
if connections_node.tag != "Connections":
2801+
connections_node = connections_node.find("Connections")
2802+
if connections_node is not None:
2803+
connections = pymvr.Connections(xml_node=connections_node)
2804+
except Exception as exc:
2805+
DMX_Log.log.warning(
2806+
f"Failed to parse MVR Connections XML for fixture {self.uuid}: {exc}"
2807+
)
2808+
27882809
return pymvr.Fixture(
27892810
name=self.user_fixture_name,
27902811
uuid=self.uuid,
@@ -2796,6 +2817,7 @@ def to_mvr_fixture(self, universe_add=False):
27962817
focus=uuid_focus_point,
27972818
color=color,
27982819
classing=self.classing,
2820+
connections=connections,
27992821
)
28002822

28012823
def focus_to_mvr_focus_point(self):

mvr.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pathlib import Path
2525
from types import SimpleNamespace
2626
import traceback
27+
from xml.etree import ElementTree
2728

2829
import bpy
2930
import pymvr
@@ -69,6 +70,17 @@ def create_local_transform_property(obj):
6970
obj["MVR Local Transform"] = trans_mtx
7071

7172

73+
def serialize_connections_xml(connections):
74+
if not connections or len(connections) == 0:
75+
return ""
76+
root = ElementTree.Element("Root")
77+
connections.to_xml(root)
78+
connections_node = root.find("Connections")
79+
if connections_node is None:
80+
return ""
81+
return ElementTree.tostring(connections_node, encoding="unicode")
82+
83+
7284
def get_matrix(obj, mtx):
7385
mtx_data = obj.matrix.matrix
7486
check_float = any(isinstance(i, float) for i in set().union(sum(mtx_data, [])))
@@ -773,6 +785,7 @@ def add_mvr_fixture(
773785
for address in fixture.addresses.addresses
774786
if address.address > 0
775787
]
788+
connections_xml = serialize_connections_xml(fixture.connections)
776789
null_matrix = pymvr.Matrix([[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
777790
# ensure that fixture is not scaled to 0
778791
if fixture.matrix == null_matrix:
@@ -807,6 +820,8 @@ def add_mvr_fixture(
807820
classing=fixture.classing,
808821
user_fixture_name=fixture.name,
809822
)
823+
existing_fixture.mvr_connections_xml = connections_xml
824+
added_fixture = existing_fixture
810825
else:
811826
if isinstance(fixture.color, str):
812827
fixture.color = pymvr.Color(str_repr=fixture.color)
@@ -829,6 +844,9 @@ def add_mvr_fixture(
829844
classing=fixture.classing,
830845
user_fixture_name=fixture.name,
831846
)
847+
added_fixture = dmx.findFixtureByUUID(fixture.uuid)
848+
if added_fixture:
849+
added_fixture.mvr_connections_xml = connections_xml
832850

833851
if parent_object is not None:
834852
direct_fixture_children.append(
@@ -852,7 +870,6 @@ def add_mvr_fixture(
852870
dump.append(fixture.uuid)
853871
group.dump = json.dumps(dump)
854872

855-
added_fixture = dmx.findFixtureByUUID(fixture.uuid)
856873
if added_fixture:
857874
added_fixture["layer_name"] = layer_collection.name
858875
added_fixture["layer_uuid"] = layer_collection.get("UUID", None)

0 commit comments

Comments
 (0)