diff --git a/plugins/XmlMaterialProfile/XmlMaterialProfile.py b/plugins/XmlMaterialProfile/XmlMaterialProfile.py index df148c19f1..dec988ad15 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialProfile.py +++ b/plugins/XmlMaterialProfile/XmlMaterialProfile.py @@ -3,7 +3,10 @@ import copy import io -from typing import List, Optional +import json #To parse the product-to-id mapping file. +import os.path #To find the product-to-id mapping. +import sys +from typing import Dict, Optional import xml.etree.ElementTree as ET from UM.Resources import Resources @@ -11,6 +14,7 @@ from UM.Logger import Logger from cura.CuraApplication import CuraApplication import UM.Dictionary +from UM.PluginRegistry import PluginRegistry from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.ContainerRegistry import ContainerRegistry @@ -211,9 +215,7 @@ class XmlMaterialProfile(InstanceContainer): machine_container_map[definition_id] = container # Map machine human-readable names to IDs - product_id_map = {} - for container in registry.findDefinitionContainersMetadata(type = "machine"): - product_id_map[container["name"]] = container["id"] + product_id_map = self.getProductIdMap() for definition_id, container in machine_container_map.items(): definition = container.getDefinition() @@ -513,9 +515,7 @@ class XmlMaterialProfile(InstanceContainer): self._dirty = False # Map machine human-readable names to IDs - product_id_map = {} - for container in ContainerRegistry.getInstance().findDefinitionContainersMetadata(type = "machine"): - product_id_map[container["name"]] = container["id"] + product_id_map = self.getProductIdMap() machines = data.iterfind("./um:settings/um:machine", self.__namespaces) for machine in machines: @@ -656,6 +656,16 @@ class XmlMaterialProfile(InstanceContainer): else: return material_name + ## Gets a mapping from product names in the XML files to their definition + # IDs. + # + # This loads the mapping from a file. + @classmethod + def getProductIdMap(cls) -> Dict[str, str]: + product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json") + with open(product_to_id_file) as f: + return json.load(f) + ## Parse the value of the "material compatible" property. def _parseCompatibleValue(self, value: str): return value in {"yes", "unknown"} diff --git a/plugins/XmlMaterialProfile/product_to_id.json b/plugins/XmlMaterialProfile/product_to_id.json new file mode 100644 index 0000000000..d6b8f3bade --- /dev/null +++ b/plugins/XmlMaterialProfile/product_to_id.json @@ -0,0 +1,12 @@ +{ + "Ultimaker 2": "ultimaker2", + "Ultimaker 2 Extended": "ultimaker2_extended", + "Ultimaker 2 Extended+": "ultimaker2_extended_plus", + "Ultimaker 2 Go": "ultimaker2_go", + "Ultimaker 2+": "ultimaker2_plus", + "Ultimaker 3": "ultimaker3", + "Ultimaker 3 Extended": "ultimaker3_extended", + "Ultimaker Original": "ultimaker_original", + "Ultimaker Original+": "ultimaker_original_plus", + "IMADE3D JellyBOX": "imade3d_jellybox" +} \ No newline at end of file