ThreeMFWorkspaceReader.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. from UM.Workspace.WorkspaceReader import WorkspaceReader
  2. from UM.Application import Application
  3. from UM.Logger import Logger
  4. from UM.i18n import i18nCatalog
  5. from UM.Settings.ContainerStack import ContainerStack
  6. from UM.Settings.DefinitionContainer import DefinitionContainer
  7. from UM.Settings.InstanceContainer import InstanceContainer
  8. from UM.Settings.ContainerRegistry import ContainerRegistry
  9. from UM.MimeTypeDatabase import MimeTypeDatabase
  10. from UM.Job import Job
  11. from UM.Preferences import Preferences
  12. from .WorkspaceDialog import WorkspaceDialog
  13. import xml.etree.ElementTree as ET
  14. from cura.Settings.ExtruderManager import ExtruderManager
  15. import zipfile
  16. import io
  17. import configparser
  18. i18n_catalog = i18nCatalog("cura")
  19. ## Base implementation for reading 3MF workspace files.
  20. class ThreeMFWorkspaceReader(WorkspaceReader):
  21. def __init__(self):
  22. super().__init__()
  23. self._supported_extensions = [".3mf"]
  24. self._dialog = WorkspaceDialog()
  25. self._3mf_mesh_reader = None
  26. self._container_registry = ContainerRegistry.getInstance()
  27. self._definition_container_suffix = ContainerRegistry.getMimeTypeForContainer(DefinitionContainer).preferredSuffix
  28. self._material_container_suffix = None # We have to wait until all other plugins are loaded before we can set it
  29. self._instance_container_suffix = ContainerRegistry.getMimeTypeForContainer(InstanceContainer).preferredSuffix
  30. self._container_stack_suffix = ContainerRegistry.getMimeTypeForContainer(ContainerStack).preferredSuffix
  31. self._resolve_strategies = {}
  32. self._id_mapping = {}
  33. ## Get a unique name based on the old_id. This is different from directly calling the registry in that it caches results.
  34. # This has nothing to do with speed, but with getting consistent new naming for instances & objects.
  35. def getNewId(self, old_id):
  36. if old_id not in self._id_mapping:
  37. self._id_mapping[old_id] = self._container_registry.uniqueName(old_id)
  38. return self._id_mapping[old_id]
  39. def preRead(self, file_name):
  40. self._3mf_mesh_reader = Application.getInstance().getMeshFileHandler().getReaderForFile(file_name)
  41. if self._3mf_mesh_reader and self._3mf_mesh_reader.preRead(file_name) == WorkspaceReader.PreReadResult.accepted:
  42. pass
  43. else:
  44. Logger.log("w", "Could not find reader that was able to read the scene data for 3MF workspace")
  45. return WorkspaceReader.PreReadResult.failed
  46. machine_name = ""
  47. machine_type = ""
  48. variant_type_name = i18n_catalog.i18nc("@label", "Nozzle")
  49. num_extruders = 0
  50. # Check if there are any conflicts, so we can ask the user.
  51. archive = zipfile.ZipFile(file_name, "r")
  52. cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
  53. container_stack_files = [name for name in cura_file_names if name.endswith(self._container_stack_suffix)]
  54. self._resolve_strategies = {"machine": None, "quality_changes": None, "material": None}
  55. machine_conflict = False
  56. quality_changes_conflict = False
  57. for container_stack_file in container_stack_files:
  58. container_id = self._stripFileToId(container_stack_file)
  59. serialized = archive.open(container_stack_file).read().decode("utf-8")
  60. if machine_name == "":
  61. machine_name = self._getMachineNameFromSerializedStack(serialized)
  62. stacks = self._container_registry.findContainerStacks(id=container_id)
  63. if stacks:
  64. # Check if there are any changes at all in any of the container stacks.
  65. id_list = self._getContainerIdListFromSerialized(serialized)
  66. for index, container_id in enumerate(id_list):
  67. if stacks[0].getContainer(index).getId() != container_id:
  68. machine_conflict = True
  69. Job.yieldThread()
  70. definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
  71. for definition_container_file in definition_container_files:
  72. container_id = self._stripFileToId(definition_container_file)
  73. definitions = self._container_registry.findDefinitionContainers(id=container_id)
  74. if not definitions:
  75. definition_container = DefinitionContainer(container_id)
  76. definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
  77. else:
  78. definition_container = definitions[0]
  79. if definition_container.getMetaDataEntry("type") != "extruder":
  80. machine_type = definition_container.getName()
  81. variant_type_name = definition_container.getMetaDataEntry("variants_name", variant_type_name)
  82. else:
  83. num_extruders += 1
  84. Job.yieldThread()
  85. if num_extruders == 0:
  86. num_extruders = 1 # No extruder stacks found, which means there is one extruder
  87. extruders = num_extruders * [""]
  88. material_labels = []
  89. material_conflict = False
  90. xml_material_profile = self._getXmlProfileClass()
  91. if self._material_container_suffix is None:
  92. self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).preferredSuffix
  93. if xml_material_profile:
  94. material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
  95. for material_container_file in material_container_files:
  96. container_id = self._stripFileToId(material_container_file)
  97. materials = self._container_registry.findInstanceContainers(id=container_id)
  98. material_labels.append(self._getMaterialLabelFromSerialized(archive.open(material_container_file).read().decode("utf-8")))
  99. if materials and not materials[0].isReadOnly(): # Only non readonly materials can be in conflict
  100. material_conflict = True
  101. Job.yieldThread()
  102. # Check if any quality_changes instance container is in conflict.
  103. instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
  104. quality_name = ""
  105. quality_type = ""
  106. num_settings_overriden_by_quality_changes = 0 # How many settings are changed by the quality changes
  107. num_user_settings = 0
  108. for instance_container_file in instance_container_files:
  109. container_id = self._stripFileToId(instance_container_file)
  110. instance_container = InstanceContainer(container_id)
  111. # Deserialize InstanceContainer by converting read data from bytes to string
  112. instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
  113. container_type = instance_container.getMetaDataEntry("type")
  114. if container_type == "quality_changes":
  115. quality_name = instance_container.getName()
  116. num_settings_overriden_by_quality_changes += len(instance_container._instances)
  117. # Check if quality changes already exists.
  118. quality_changes = self._container_registry.findInstanceContainers(id = container_id)
  119. if quality_changes:
  120. # Check if there really is a conflict by comparing the values
  121. if quality_changes[0] != instance_container:
  122. quality_changes_conflict = True
  123. elif container_type == "quality":
  124. # If the quality name is not set (either by quality or changes, set it now)
  125. # Quality changes should always override this (as they are "on top")
  126. if quality_name == "":
  127. quality_name = instance_container.getName()
  128. quality_type = instance_container.getName()
  129. elif container_type == "user":
  130. num_user_settings += len(instance_container._instances)
  131. Job.yieldThread()
  132. num_visible_settings = 0
  133. try:
  134. temp_preferences = Preferences()
  135. temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
  136. visible_settings_string = temp_preferences.getValue("general/visible_settings")
  137. if visible_settings_string is not None:
  138. num_visible_settings = len(visible_settings_string.split(";"))
  139. active_mode = temp_preferences.getValue("cura/active_mode")
  140. if not active_mode:
  141. active_mode = Preferences.getInstance().getValue("cura/active_mode")
  142. except KeyError:
  143. # If there is no preferences file, it's not a workspace, so notify user of failure.
  144. Logger.log("w", "File %s is not a valid workspace.", file_name)
  145. return WorkspaceReader.PreReadResult.failed
  146. # Show the dialog, informing the user what is about to happen.
  147. self._dialog.setMachineConflict(machine_conflict)
  148. self._dialog.setQualityChangesConflict(quality_changes_conflict)
  149. self._dialog.setMaterialConflict(material_conflict)
  150. self._dialog.setNumVisibleSettings(num_visible_settings)
  151. self._dialog.setQualityName(quality_name)
  152. self._dialog.setQualityType(quality_type)
  153. self._dialog.setNumSettingsOverridenByQualityChanges(num_settings_overriden_by_quality_changes)
  154. self._dialog.setNumUserSettings(num_user_settings)
  155. self._dialog.setActiveMode(active_mode)
  156. self._dialog.setMachineName(machine_name)
  157. self._dialog.setMaterialLabels(material_labels)
  158. self._dialog.setMachineType(machine_type)
  159. self._dialog.setExtruders(extruders)
  160. self._dialog.setVariantType(variant_type_name)
  161. self._dialog.setHasObjectsOnPlate(Application.getInstance().getPlatformActivity)
  162. self._dialog.show()
  163. # Block until the dialog is closed.
  164. self._dialog.waitForClose()
  165. if self._dialog.getResult() == {}:
  166. return WorkspaceReader.PreReadResult.cancelled
  167. self._resolve_strategies = self._dialog.getResult()
  168. return WorkspaceReader.PreReadResult.accepted
  169. def read(self, file_name):
  170. archive = zipfile.ZipFile(file_name, "r")
  171. cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
  172. # Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
  173. # parsing code.
  174. temp_preferences = Preferences()
  175. temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
  176. # Copy a number of settings from the temp preferences to the global
  177. global_preferences = Preferences.getInstance()
  178. visible_settings = temp_preferences.getValue("general/visible_settings")
  179. if visible_settings is None:
  180. Logger.log("w", "Workspace did not contain visible settings. Leaving visibility unchanged")
  181. else:
  182. global_preferences.setValue("general/visible_settings", visible_settings)
  183. categories_expanded = temp_preferences.getValue("cura/categories_expanded")
  184. if categories_expanded is None:
  185. Logger.log("w", "Workspace did not contain expanded categories. Leaving them unchanged")
  186. else:
  187. global_preferences.setValue("cura/categories_expanded", categories_expanded)
  188. Application.getInstance().expandedCategoriesChanged.emit() # Notify the GUI of the change
  189. self._id_mapping = {}
  190. # We don't add containers right away, but wait right until right before the stack serialization.
  191. # We do this so that if something goes wrong, it's easier to clean up.
  192. containers_to_add = []
  193. # TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
  194. # TODO: cases that the container loaded is the same (most notable in materials & definitions).
  195. # TODO: It might be possible that we need to add smarter checking in the future.
  196. Logger.log("d", "Workspace loading is checking definitions...")
  197. # Get all the definition files & check if they exist. If not, add them.
  198. definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
  199. for definition_container_file in definition_container_files:
  200. container_id = self._stripFileToId(definition_container_file)
  201. definitions = self._container_registry.findDefinitionContainers(id=container_id)
  202. if not definitions:
  203. definition_container = DefinitionContainer(container_id)
  204. definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
  205. self._container_registry.addContainer(definition_container)
  206. Job.yieldThread()
  207. Logger.log("d", "Workspace loading is checking materials...")
  208. material_containers = []
  209. # Get all the material files and check if they exist. If not, add them.
  210. xml_material_profile = self._getXmlProfileClass()
  211. if self._material_container_suffix is None:
  212. self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).suffixes[0]
  213. if xml_material_profile:
  214. material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
  215. for material_container_file in material_container_files:
  216. container_id = self._stripFileToId(material_container_file)
  217. materials = self._container_registry.findInstanceContainers(id=container_id)
  218. if not materials:
  219. material_container = xml_material_profile(container_id)
  220. material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
  221. containers_to_add.append(material_container)
  222. else:
  223. if not materials[0].isReadOnly(): # Only create new materials if they are not read only.
  224. if self._resolve_strategies["material"] == "override":
  225. materials[0].deserialize(archive.open(material_container_file).read().decode("utf-8"))
  226. elif self._resolve_strategies["material"] == "new":
  227. # Note that we *must* deserialize it with a new ID, as multiple containers will be
  228. # auto created & added.
  229. material_container = xml_material_profile(self.getNewId(container_id))
  230. material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
  231. containers_to_add.append(material_container)
  232. material_containers.append(material_container)
  233. Job.yieldThread()
  234. Logger.log("d", "Workspace loading is checking instance containers...")
  235. # Get quality_changes and user profiles saved in the workspace
  236. instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
  237. user_instance_containers = []
  238. quality_changes_instance_containers = []
  239. for instance_container_file in instance_container_files:
  240. container_id = self._stripFileToId(instance_container_file)
  241. instance_container = InstanceContainer(container_id)
  242. # Deserialize InstanceContainer by converting read data from bytes to string
  243. instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
  244. container_type = instance_container.getMetaDataEntry("type")
  245. Job.yieldThread()
  246. if container_type == "user":
  247. # Check if quality changes already exists.
  248. user_containers = self._container_registry.findInstanceContainers(id=container_id)
  249. if not user_containers:
  250. containers_to_add.append(instance_container)
  251. else:
  252. if self._resolve_strategies["machine"] == "override" or self._resolve_strategies["machine"] is None:
  253. user_containers[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
  254. elif self._resolve_strategies["machine"] == "new":
  255. # The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
  256. extruder_id = instance_container.getMetaDataEntry("extruder", None)
  257. if extruder_id:
  258. new_id = self.getNewId(extruder_id) + "_current_settings"
  259. instance_container._id = new_id
  260. instance_container.setName(new_id)
  261. instance_container.setMetaDataEntry("extruder", self.getNewId(extruder_id))
  262. containers_to_add.append(instance_container)
  263. machine_id = instance_container.getMetaDataEntry("machine", None)
  264. if machine_id:
  265. new_id = self.getNewId(machine_id) + "_current_settings"
  266. instance_container._id = new_id
  267. instance_container.setName(new_id)
  268. instance_container.setMetaDataEntry("machine", self.getNewId(machine_id))
  269. containers_to_add.append(instance_container)
  270. user_instance_containers.append(instance_container)
  271. elif container_type == "quality_changes":
  272. # Check if quality changes already exists.
  273. quality_changes = self._container_registry.findInstanceContainers(id = container_id)
  274. if not quality_changes:
  275. containers_to_add.append(instance_container)
  276. else:
  277. if self._resolve_strategies["quality_changes"] == "override":
  278. quality_changes[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
  279. elif self._resolve_strategies["quality_changes"] is None:
  280. # The ID already exists, but nothing in the values changed, so do nothing.
  281. pass
  282. quality_changes_instance_containers.append(instance_container)
  283. else:
  284. continue
  285. # Add all the containers right before we try to add / serialize the stack
  286. for container in containers_to_add:
  287. self._container_registry.addContainer(container)
  288. container.setDirty(True)
  289. # Get the stack(s) saved in the workspace.
  290. Logger.log("d", "Workspace loading is checking stacks containers...")
  291. container_stack_files = [name for name in cura_file_names if name.endswith(self._container_stack_suffix)]
  292. global_stack = None
  293. extruder_stacks = []
  294. container_stacks_added = []
  295. try:
  296. for container_stack_file in container_stack_files:
  297. container_id = self._stripFileToId(container_stack_file)
  298. # Check if a stack by this ID already exists;
  299. container_stacks = self._container_registry.findContainerStacks(id=container_id)
  300. if container_stacks:
  301. stack = container_stacks[0]
  302. if self._resolve_strategies["machine"] == "override":
  303. # TODO: HACK
  304. # There is a machine, check if it has authenticationd data. If so, keep that data.
  305. network_authentication_id = container_stacks[0].getMetaDataEntry("network_authentication_id")
  306. network_authentication_key = container_stacks[0].getMetaDataEntry("network_authentication_key")
  307. container_stacks[0].deserialize(archive.open(container_stack_file).read().decode("utf-8"))
  308. if network_authentication_id:
  309. container_stacks[0].addMetaDataEntry("network_authentication_id", network_authentication_id)
  310. if network_authentication_key:
  311. container_stacks[0].addMetaDataEntry("network_authentication_key", network_authentication_key)
  312. elif self._resolve_strategies["machine"] == "new":
  313. new_id = self.getNewId(container_id)
  314. stack = ContainerStack(new_id)
  315. stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))
  316. # Ensure a unique ID and name
  317. stack._id = new_id
  318. # Extruder stacks are "bound" to a machine. If we add the machine as a new one, the id of the
  319. # bound machine also needs to change.
  320. if stack.getMetaDataEntry("machine", None):
  321. stack.setMetaDataEntry("machine", self.getNewId(stack.getMetaDataEntry("machine")))
  322. if stack.getMetaDataEntry("type") != "extruder_train":
  323. # Only machines need a new name, stacks may be non-unique
  324. stack.setName(self._container_registry.uniqueName(stack.getName()))
  325. container_stacks_added.append(stack)
  326. self._container_registry.addContainer(stack)
  327. else:
  328. Logger.log("w", "Resolve strategy of %s for machine is not supported", self._resolve_strategies["machine"])
  329. else:
  330. stack = ContainerStack(container_id)
  331. # Deserialize stack by converting read data from bytes to string
  332. stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))
  333. container_stacks_added.append(stack)
  334. self._container_registry.addContainer(stack)
  335. if stack.getMetaDataEntry("type") == "extruder_train":
  336. extruder_stacks.append(stack)
  337. else:
  338. global_stack = stack
  339. Job.yieldThread()
  340. except:
  341. Logger.logException("w", "We failed to serialize the stack. Trying to clean up.")
  342. # Something went really wrong. Try to remove any data that we added.
  343. for container in containers_to_add:
  344. self._container_registry.getInstance().removeContainer(container.getId())
  345. for container in container_stacks_added:
  346. self._container_registry.getInstance().removeContainer(container.getId())
  347. return None
  348. if self._resolve_strategies["machine"] == "new":
  349. # A new machine was made, but it was serialized with the wrong user container. Fix that now.
  350. for container in user_instance_containers:
  351. extruder_id = container.getMetaDataEntry("extruder", None)
  352. if extruder_id:
  353. for extruder in extruder_stacks:
  354. if extruder.getId() == extruder_id:
  355. extruder.replaceContainer(0, container)
  356. continue
  357. machine_id = container.getMetaDataEntry("machine", None)
  358. if machine_id:
  359. if global_stack.getId() == machine_id:
  360. global_stack.replaceContainer(0, container)
  361. continue
  362. if self._resolve_strategies["quality_changes"] == "new":
  363. # Quality changes needs to get a new ID, added to registry and to the right stacks
  364. for container in quality_changes_instance_containers:
  365. old_id = container.getId()
  366. container.setName(self._container_registry.uniqueName(container.getName()))
  367. # We're not really supposed to change the ID in normal cases, but this is an exception.
  368. container._id = self.getNewId(container.getId())
  369. # The container was not added yet, as it didn't have an unique ID. It does now, so add it.
  370. self._container_registry.addContainer(container)
  371. # Replace the quality changes container
  372. old_container = global_stack.findContainer({"type": "quality_changes"})
  373. if old_container.getId() == old_id:
  374. quality_changes_index = global_stack.getContainerIndex(old_container)
  375. global_stack.replaceContainer(quality_changes_index, container)
  376. continue
  377. for stack in extruder_stacks:
  378. old_container = stack.findContainer({"type": "quality_changes"})
  379. if old_container.getId() == old_id:
  380. quality_changes_index = stack.getContainerIndex(old_container)
  381. stack.replaceContainer(quality_changes_index, container)
  382. if self._resolve_strategies["material"] == "new":
  383. for material in material_containers:
  384. old_material = global_stack.findContainer({"type": "material"})
  385. if old_material.getId() in self._id_mapping:
  386. material_index = global_stack.getContainerIndex(old_material)
  387. global_stack.replaceContainer(material_index, material)
  388. continue
  389. for stack in extruder_stacks:
  390. old_material = stack.findContainer({"type": "material"})
  391. if old_material.getId() in self._id_mapping:
  392. material_index = stack.getContainerIndex(old_material)
  393. stack.replaceContainer(material_index, material)
  394. continue
  395. for stack in extruder_stacks:
  396. ExtruderManager.getInstance().registerExtruder(stack, global_stack.getId())
  397. else:
  398. # Machine has no extruders, but it needs to be registered with the extruder manager.
  399. ExtruderManager.getInstance().registerExtruder(None, global_stack.getId())
  400. Logger.log("d", "Workspace loading is notifying rest of the code of changes...")
  401. # Notify everything/one that is to notify about changes.
  402. global_stack.containersChanged.emit(global_stack.getTop())
  403. for stack in extruder_stacks:
  404. stack.setNextStack(global_stack)
  405. stack.containersChanged.emit(stack.getTop())
  406. # Actually change the active machine.
  407. Application.getInstance().setGlobalContainerStack(global_stack)
  408. # Load all the nodes / meshdata of the workspace
  409. nodes = self._3mf_mesh_reader.read(file_name)
  410. if nodes is None:
  411. nodes = []
  412. return nodes
  413. def _stripFileToId(self, file):
  414. return file.replace("Cura/", "").split(".")[0]
  415. def _getXmlProfileClass(self):
  416. return self._container_registry.getContainerForMimeType(MimeTypeDatabase.getMimeType("application/x-ultimaker-material-profile"))
  417. ## Get the list of ID's of all containers in a container stack by partially parsing it's serialized data.
  418. def _getContainerIdListFromSerialized(self, serialized):
  419. parser = configparser.ConfigParser(interpolation=None, empty_lines_in_values=False)
  420. parser.read_string(serialized)
  421. container_ids = []
  422. if "containers" in parser:
  423. for index, container_id in parser.items("containers"):
  424. container_ids.append(container_id)
  425. elif parser.has_option("general", "containers"):
  426. container_string = parser["general"].get("containers", "")
  427. container_list = container_string.split(",")
  428. container_ids = [container_id for container_id in container_list if container_id != ""]
  429. return container_ids
  430. def _getMachineNameFromSerializedStack(self, serialized):
  431. parser = configparser.ConfigParser(interpolation=None, empty_lines_in_values=False)
  432. parser.read_string(serialized)
  433. return parser["general"].get("name", "")
  434. def _getMaterialLabelFromSerialized(self, serialized):
  435. data = ET.fromstring(serialized)
  436. metadata = data.iterfind("./um:metadata/um:name/um:label", {"um": "http://www.ultimaker.com/material"})
  437. for entry in metadata:
  438. return entry.text
  439. pass