def METHOD_NAME(self):
    machine_manager = self._application.getMachineManager()
    global_stack = machine_manager.activeMachine
    definition = global_stack.definition
    if definition.getProperty("machine_gcode_flavor", "value") != "UltiGCode" or definition.getMetaDataEntry(
            "has_materials", False):
        # In other words: only continue for the UM2 (extended), but not for the UM2+
        return
    has_materials = global_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode"
    material_node = None
    if has_materials:
        global_stack.setMetaDataEntry("has_materials", True)
    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_stack.getMetaData():
            global_stack.removeMetaDataEntry("has_materials")
    # set materials
    for position, extruder in enumerate(global_stack.extruderList):
        if has_materials:
            approximate_diameter = extruder.getApproximateMaterialDiameter()
            variant_node = ContainerTree.getInstance().machines[global_stack.definition.getId()].variants[extruder.variant.getName()]
            material_node = variant_node.preferredMaterial(approximate_diameter)
        machine_manager.setMaterial(str(position), material_node)
    self.forceUpdate()