diff --git a/cura/CuraActions.py b/cura/CuraActions.py index 5c89232639..64db7c9372 100644 --- a/cura/CuraActions.py +++ b/cura/CuraActions.py @@ -9,6 +9,7 @@ from UM.Event import CallFunctionEvent from UM.Application import Application from UM.Math.Vector import Vector from UM.Scene.Selection import Selection +from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator from UM.Operations.GroupedOperation import GroupedOperation from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation from UM.Operations.SetTransformOperation import SetTransformOperation @@ -81,9 +82,31 @@ class CuraActions(QObject): @pyqtSlot(str) def setExtruderForSelection(self, extruder_id: str) -> None: operation = GroupedOperation() + + nodes_to_change = [] for node in Selection.getAllSelectedObjects(): + # Do not change any nodes that already have the right extruder set. if node.callDecoration("getActiveExtruder") == extruder_id: continue + + # If the node is a group, apply the active extruder to all children of the group. + if node.callDecoration("isGroup"): + for grouped_node in BreadthFirstIterator(node): + if grouped_node.callDecoration("getActiveExtruder") == extruder_id: + continue + + if grouped_node.callDecoration("isGroup"): + continue + + nodes_to_change.append(grouped_node) + continue + + nodes_to_change.append(node) + + if not nodes_to_change: + return + + for node in nodes_to_change: operation.addOperation(SetObjectExtruderOperation(node, extruder_id)) operation.push()