Jump to content
UltiMaker Community of 3D Printing Experts

Add View only values to Post Processing Script


raferde

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 - jay.holweger@gmail.com
 
#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

      • UltiMaker Cura 5.3 stable released
        In this stable release, Cura 5.3 achieves yet another huge leap forward in 3D printing thanks to material interlocking! As well as introducing an expanded recommended print settings menu and lots of print quality improvements. Not to mention, a whole bunch of new printer profiles for non-UltiMaker printers!
          • Thanks
          • Like
        • 24 replies
      • Here it is. The new UltiMaker S7
        The UltiMaker S7 is built on the success of the UltiMaker S5 and its design decisions were heavily based on feedback from customers.
         
         
        So what’s new?
        The obvious change is the S7’s height. It now includes an integrated Air Manager. This filters the exhaust air of every print and also improves build temperature stability. To further enclose the build chamber the S7 only has one magnetically latched door.
         
        The build stack has also been completely redesigned. A PEI-coated flexible steel build plate makes a big difference to productivity. Not only do you not need tools to pop a printed part off. But we also don’t recommend using or adhesion structures for UltiMaker materials (except PC, because...it’s PC). Along with that, 4 pins and 25 magnets make it easy to replace the flex plate perfectly – even with one hand.
         
        The re-engineered print head has an inductive sensor which reduces noise when probing the build plate. This effectively makes it much harder to not achieve a perfect first layer, improving overall print success. We also reversed the front fan direction (fewer plastic hairs, less maintenance), made the print core door magnets stronger, and add a sensor that helps avoid flooding.
         

         
        The UltiMaker S7 also includes quality of life improvements:
        Reliable bed tilt compensation (no more thumbscrews) 2.4 and 5 GHz Wi-Fi A 1080p camera (mounted higher for a better view) Compatibility with 280+ Marketplace materials Compatibility with S5 project files (no reslicing needed) And a whole lot more  
        Curious to see the S7 in action?
        We’re hosting a free tech demo on February 7.
        It will be live and you can ask any questions to our CTO, Miguel Calvo.
        Register here for the Webinar
          • Like
        • 18 replies
      • UltiMaker Cura Alpha 🎄 Tree Support Spotlight 🎄
        Are you a fan of tree support, but dislike the removal process and the amount of filament it uses? Then we would like to invite you to try this special release of UltiMaker Cura. Brought to you by our special community contributor @thomasrahm
         
        We generated a special version of Cura 5.2 called 5.3.0 Alpha + Xmas. The only changes we introduced compared to UltiMaker Cura 5.2.1 are those which are needed for the new supports. So keep in mind, this is not a sneak peek for Cura 5.3 (there are some really cool new features coming up) but a spotlight release highlighting this new version of tree supports.  
          • Like
        • 22 replies
    ×
    ×
    • Create New...