From 7471b00eff6537266bfebba2a217e53fd141728b Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 8 Aug 2016 18:16:22 +0200 Subject: [PATCH] Set the material container to a sane default --- MachineSettingsAction.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/MachineSettingsAction.py b/MachineSettingsAction.py index 130ce642c9..68dbbb9b62 100644 --- a/MachineSettingsAction.py +++ b/MachineSettingsAction.py @@ -60,15 +60,28 @@ class MachineSettingsAction(MachineAction): if definition.getProperty("machine_gcode_flavor", "value") == "UltiGCode" and not definition.getMetaDataEntry("has_materials", False): has_materials = global_container_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode" - # NB: this metadata entry is stored in an ini, and ini files are parsed as strings only. - # because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False. + material_container = global_container_stack.findContainer({"type": "material"}) + material_index = global_container_stack.getContainerIndex(material_container) + if has_materials: if "has_materials" in global_container_stack.getMetaData(): global_container_stack.setMetaDataEntry("has_materials", True) else: global_container_stack.addMetaDataEntry("has_materials", True) + + # Set the material container to a sane default + if material_container.getId() == "empty_material": + search_criteria = { "type": "material", "definition": "fdmprinter", "id": "*pla*" } + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**search_criteria) + if containers: + global_container_stack.replaceContainer(material_index, containers[0]) else: + # The metadata entry is stored in an ini, and ini files are parsed as strings only. + # Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False. if "has_materials" in global_container_stack.getMetaData(): global_container_stack.removeMetaDataEntry("has_materials") + empty_material = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = "empty_material")[0] + global_container_stack.replaceContainer(material_index, empty_material) + UM.Application.getInstance().globalContainerStackChanged.emit() \ No newline at end of file