Fix possibly wrong returned initial extruder

CURA-12099
This commit is contained in:
Erwan MATHIEU 2025-04-17 13:25:24 +02:00
parent afc22638ba
commit c28ab219a0

View file

@ -15,6 +15,7 @@ from UM.Scene.Selection import Selection
from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
from UM.Settings.ContainerRegistry import ContainerRegistry # Finding containers by ID.
from cura.Machines.ContainerTree import ContainerTree
from cura.Settings.ExtruderStack import ExtruderStack
from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING, Union
@ -304,6 +305,11 @@ class ExtruderManager(QObject):
Logger.log("e", "Unable to find one or more of the extruders in %s", used_extruder_stack_ids)
return []
def getFirstUsedExtruderStack(self)-> ExtruderStack:
used_extruders = self.getUsedExtruderStacks()
sorted_extruders = sorted(used_extruders, key=lambda extruder: extruder.getValue("extruder_nr"))
return sorted_extruders[0]
def getInitialExtruderNr(self) -> int:
"""Get the extruder that the print will start with.
@ -320,8 +326,7 @@ class ExtruderManager(QObject):
skirt_brim_extruder_nr = global_stack.getProperty("skirt_brim_extruder_nr", "value")
# if the skirt_brim_extruder_nr is -1, then we use the first used extruder
if skirt_brim_extruder_nr == -1:
used_extruders = self.getUsedExtruderStacks()
return used_extruders[0].position
return self.getFirstUsedExtruderStack().getValue("extruder_nr")
else:
return skirt_brim_extruder_nr
if adhesion_type == "raft":
@ -332,7 +337,7 @@ class ExtruderManager(QObject):
return global_stack.getProperty("support_infill_extruder_nr", "value")
# REALLY no adhesion? Use the first used extruder.
return self.getUsedExtruderStacks()[0].getProperty("extruder_nr", "value")
return self.getFirstUsedExtruderStack().getValue("extruder_nr")
def removeMachineExtruders(self, machine_id: str) -> None:
"""Removes the container stack and user profile for the extruders for a specific machine.