Jump to content

Recommended Posts

Posted · Add View only values to Post Processing Script

I have updated the ColorMix 2-1 Post Processing script to mix 3 colors.  I have found that to make it work I need to show the Start and End Mix ratios for all of the extruders.  The total for all of the extruders start and end ration has to add up to 100%.  It works to show all values since setting the first two extruders will default the third to the remaining amount.  The problem shows up if you edit either value for the third extruder since changing the value overrides the "value" setting.  

Is there a way to make a setting show on the screen but be view only?

# ColorMix script - 3-1 extruder color mix and blending
# This script is specific for the Geeetech A30T dual extruder but should work with other Marlin printers.
# It runs with the PostProcessingPlugin which is released under the terms of the AGPLv3 or higher.
# This script is licensed under the Creative Commons - Attribution - Share Alike (CC BY-SA) terms
 
#Authors of the ColorMix for A30T plug-in / script:
# Written by Jay Holweger - [email protected]
 
#history / change-log:
#V1.0.0 - Initial Copy of ColorMix 2-1
 
import re #To perform the search and replace.
from ..Script import Script
 
class ColorMixA30T(Script😞
    def __init__(self😞
        super().__init__()
 
    def getSettingDataString(self😞
        return """{
            "name":"ColorMix A30T V1.0.0",
            "key":"ColorMix A30T",
            "metadata": {},
            "version": 2,
            "settings":
            {
                "units_of_measurement":
                {
                    "label": "Units",
                    "description": "Input value as mm or layer number.",
                    "type": "enum",
                    "options": {"mm":"mm","layer":"Layer"},
                    "default_value": "layer"
                },
                "object_number":
                {
                    "label": "Object Number",
                    "description": "Select model to apply to for print one at a time print sequence. 0 = everything",
                    "type": "int",
                    "default_value": 0,
                    "minimum_value": "0"
                },
                "start_height":
                {
                    "label": "Start Height",
                    "description": "Value to start at (mm or layer)",
                    "type": "float",
                    "default_value": 0,
                    "minimum_value": "0"
                },
                "behavior":
                {
                    "label": "Fixed or blend",
                    "description": "Select Fixed (set new mixture) or Blend mode (dynamic mix)",
                    "type": "enum",
                    "options": {"fixed_value":"Fixed","blend_value":"Blend"},
                    "default_value": "fixed_value"
                },
                "finish_height":
                {
                    "label": "Finish Height",
                    "description": "Value to stop at (mm or layer)",
                    "type": "float",
                    "default_value": 0,
                    "minimum_value": "0",
                    "minimum_value_warning": "start_height",
                    "enabled": "behavior == 'blend_value'"
                },
                "mix0_start":
                {
                    "label": "Extruder 1 Start mix ratio",
                    "description": "First extruder percentage 0-100",
                    "type": "float",
                    "default_value": 100,
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100"
                },
                "mix0_finish":
                {
                    "label": "Extruder 1 End mix ratio",
                    "description": "First extruder percentage 0-100 to finish blend",
                    "type": "float",
                    "default_value": 0,
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100",
                    "enabled": "behavior == 'blend_value'"
                },
                "mix1_start":
                {
                    "label": "Extruder 2 Start mix ratio",
                    "description": "Second extruder percentage 0-100",
                    "type": "float",
                    "default_value": 0,
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100"
                },
                "mix1_finish":
                {
                    "label": "Extruder 2 End mix ratio",
                    "description": "Second extruder percentage 0-100 to finish blend",
                    "type": "float",
                    "default_value": 100,
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100",
                    "enabled": "behavior == 'blend_value'"
                },
                "virtual_tool":
                {
                    "label": "Virtual Tool",
                    "description": "Number of the virtual tool to set",
                    "type": "int",
                    "default_value": 12,
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "16"
                },
                "dont_touch":
                {
                    "label": "Do not change Extruder 3",
                    "description": "Do not change the values below this box.  Extruder 3 is calculated from the other extruder values",
                    "type": "str",
                    "default_value": "It's calculated for you"
                },
                "mix2_start":
                {
                    "label": "Extruder 3 Start mix ratio",
                    "description": "Third extruder percentage 0-100",
                    "type": "float",
                    "value": "(100 - mix0_start - mix1_start)",
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100"
                },
                "mix2_finish":
                {
                    "label": "Extruder 3 End mix ratio",
                    "description": "Third extruder percentage 0-100 to finish blend",
                    "type": "float",
                    "value": "(100 - mix0_finish - mix1_finish)",
                    "minimum_value": "0",
                    "minimum_value_warning": "0",
                    "maximum_value_warning": "100",
                    "enabled": "behavior == 'blend_value'"
                }
            }
        }"""
    def getValue(self, line, key, default = None😞 #replace default getvalue due to comment-reading feature
        if not key in line or (";" in line and line.find(key) > line.find(";") and
                                   not ";ChangeAtZ" in key and not ";LAYER:" in key😞
            return default
        subPart = line[line.find(key) + len(key):] #allows for string lengths larger than 1
        if ";ChangeAtZ" in key:
            m = re.search("^[0-4]", subPart)
        elif ";LAYER:" in key:
            m = re.search("^[+-]?[0-9]*", subPart)
        else:
            #the minus at the beginning allows for negative values, e.g. for delta printers
            m = re.search("^[-]?[0-9]*\.?[0-9]*", subPart)
        if m == None:
            return default
        try:
            return float(m.group(0))
        except:
            return default
 
    def execute(self, data😞
 
        firstHeight = self.getSettingValueByKey("start_height")
        secondHeight = self.getSettingValueByKey("finish_height")
        firstMix0 = self.getSettingValueByKey("mix0_start")
        secondMix0 = self.getSettingValueByKey("mix0_finish")
        firstMix1 = self.getSettingValueByKey("mix1_start")
        secondMix1 = self.getSettingValueByKey("mix1_finish")
        firstMix2 = 100 - self.getSettingValueByKey("mix0_start") - self.getSettingValueByKey("mix1_start")
        secondMix2 = 100 - self.getSettingValueByKey("mix0_finish") - self.getSettingValueByKey("mix1_finish")
        vTool= self.getSettingValueByKey("virtual_tool")
        modelOfInterest = self.getSettingValueByKey("object_number")
 
        #get layer height
        layerHeight = 0
        for active_layer in data:
            lines = active_layer.split("\n")
            for line in lines:
                if ";Layer height: " in line:
                    layerHeight = self.getValue(line, ";Layer height: ", layerHeight)
                    break
            if layerHeight != 0:
                break
 
        #default layerHeight if not found
        if layerHeight == 0:
            layerHeight = .2
 
        #get layers to use
        startLayer = 0
        endLayer = 0
        if self.getSettingValueByKey("units_of_measurement") == "mm":
            startLayer = round(firstHeight / layerHeight)
            endLayer = round(secondHeight / layerHeight)
        else:  #layer height shifts down by one for g-code
            if firstHeight <= 0:
                firstHeight = 1
            if secondHeight <= 0:
                secondHeight = 1  
            startLayer = firstHeight - 1
            endLayer = secondHeight - 1
        #see if one-shot
        if self.getSettingValueByKey("behavior") == "fixed_value":
            endLayer = startLayer
            firstExtruderIncrements = 0
            secondExtruderIncrements = 0
            thirdExtruderIncrements = 0
        else:  #blend
            firstExtruderIncrements = (secondMix0 - firstMix0) / (endLayer - startLayer)
            secondExtruderIncrements = (secondMix1 - firstMix1) / (endLayer - startLayer)
            thirdExtruderIncrements = (secondMix2 - firstMix2) / (endLayer - startLayer)
        firstExtruderValue = 0
        secondExtruderValue = 0
        thirdExtruderValue = 0
        index = 0
 
        #start scanning
        layer = -1
        modelNumber = 0
        for active_layer in data:
            modified_gcode = ""
            lineIndex = 0
            lines = active_layer.split("\n")
            for line in lines:
                #dont leave blanks
                if line != "":
                    modified_gcode += line + "\n"
                # find current layer
                if ";LAYER:" in line:
                    layer = self.getValue(line, ";LAYER:", layer)
                    #get model number by layer 0 repeats
                    if layer == 0:
                        modelNumber = modelNumber + 1
                    #search for layers to manipulate
                    if (layer >= startLayer) and (layer <= endLayer😞
                        #make sure correct model is selected
                        if (modelOfInterest == 0) or (modelOfInterest == modelNumber😞
                            #Delete old data if required
                            if lines[lineIndex + 4] == "T12":  
                                del lines[(lineIndex + 1):(lineIndex + 5)]
                            #add mixing commands
                            firstExtruderValue = int(((layer - startLayer) * firstExtruderIncrements) + firstMix0)
                            secondExtruderValue = int(((layer - startLayer) * secondExtruderIncrements) + firstMix1)
                            thirdExtruderValue = int(((layer - startLayer) * thirdExtruderIncrements) + firstMix2)
                            if firstExtruderValue == 100:
                                modified_gcode += "M163 S0 P1\n"
                            else:
                                modified_gcode += "M163 S0 P0.{:02d}\n".format(firstExtruderValue)
                            if secondExtruderValue == 100:  
                                modified_gcode += "M163 S1 P1\n"
                            else:
                                modified_gcode += "M163 S1 P0.{:02d}\n".format(secondExtruderValue)
                            if thirdExtruderValue == 100:  
                                modified_gcode += "M163 S2 P1\n"
                            else:
                                modified_gcode += "M163 S2 P0.{:02d}\n".format(100 - firstExtruderValue - secondExtruderValue)
                            modified_gcode += "M164 S{:02d}\n".format(vTool)
                            modified_gcode += "T{:02d}\n".format(vTool)
                lineIndex += 1  #for deleting index
            data[index] = modified_gcode
            index += 1
        return data
  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Our picks

      • Help Us Improve Cura – Join the Ultimaker Research Program
        🚀 Help Shape the Future of Cura and Digital Factory – Join Our Power User Research Program!
        We’re looking for active users of Cura and Digital Factory — across professional and educational use cases — to help us improve the next generation of our tools.
        Our Power User Research Program kicks off with a quick 15-minute interview to learn about your setup and workflows. If selected, you’ll be invited into a small group of users who get early access to features and help us shape the future of 3D printing software.

        🧪 What to Expect:
        A short 15-minute kickoff interview to help us get to know you If selected, bi-monthly research sessions (15–30 minutes) where we’ll test features, review workflows, or gather feedback Occasional invites to try out early prototypes or vote on upcoming improvements
        🎁 What You’ll Get:
         
        Selected participants receive a free 1-year Studio or Classroom license Early access to new features and tools A direct voice in what we build next
        👉 Interested? Please fill out this quick form
        Your feedback helps us make Cura Cloud more powerful, more intuitive, and more aligned with how you actually print and manage your workflow.
        Thanks for being part of the community,

        — The Ultimaker Software Team
        • 0 replies
      • Cura 5.10 stable released!
        The full stable release of Cura 5.10 has arrived, and it brings support for the new Ultimaker S8, as well as new materials and profiles for previously supported UltiMaker printers. Additionally, you can now control your models in Cura using a 3D SpaceMouse and more!
          • Like
        • 18 replies
    ×
    ×
    • Create New...