Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add or document REPLACE function #4529

Open
JesNoFear opened this issue Feb 15, 2025 · 0 comments
Open

add or document REPLACE function #4529

JesNoFear opened this issue Feb 15, 2025 · 0 comments

Comments

@JesNoFear
Copy link

Is your feature request related to a problem? Please describe.
I am trying to provide a list of filament colors to my ERCF v2 / Happy hare, using the following string i get most of what i need
MMU_START_SETUP INITIAL_TOOL={initial_tool} REFERENCED_TOOLS=0,1,2,3,4,5,6,7,8,9,10,11 TOOL_COLORS={filament_colour[0]},{filament_colour[1]},{filament_colour[2]},{filament_colour[3]},{filament_colour[4]},{filament_colour[5]},{filament_colour[6]},{filament_colour[7]},{filament_colour[8]},{filament_colour[9]},{filament_colour[10]},{filament_colour[11]} TOOL_TEMPS={temperature[0]},{temperature[1]},{temperature[2]},{temperature[3]},{temperature[4]},{temperature[5]},{temperature[6]},{temperature[7]},{temperature[8]},{temperature[9]},{temperature[10]},{temperature[11]} TOOL_MATERIALS={filament_type[0]},{filament_type[1]},{filament_type[2]},{filament_type[3]},{filament_type[4]},{filament_type[5]},{filament_type[6]},{filament_type[7]},{filament_type[8]},{filament_type[9]},{filament_type[10]},{filament_type[11]} FILAMENT_NAMES="{filament_settings_id[0]}","{filament_settings_id[1]}","{filament_settings_id[2]}","{filament_settings_id[3]}","{filament_settings_id[4]}","{filament_settings_id[5]}","{filament_settings_id[6]}","{filament_settings_id[7]}","{filament_settings_id[8]}","{filament_settings_id[9]}","{filament_settings_id[10]}","{filament_settings_id[11]}" PURGE_VOLUMES=50,50,50,50,50,50,50,50,50,50,50,50

BUT the colors are reporting out with "#" leading (which is correct) but happy hare is expecting hex only without the leading #.

in klipper, you can use the replace function {% set fixed_color = color.replace('\x23', '') %} but i dont see that function in the slicer.

Describe the solution you'd like
the addition or documentation of replace function within the slicer

Describe how it would work
probably the most useful implementation would be to mirror the python method, though most implementations are the same.
the ability to call {filament_colour[0].replace('\x23','')} or {filament_colour[0].replace('#','')}

Describe alternatives you've considered
I tried processing it through the [print_start] macro, but does not seems to work.

[gcode_macro PRINT_START]
gcode:
    {% set BED_TEMP = params.BED|default(printer.heater_bed.target)|float %}
    {% set EXTRUDER_TEMP = params.EXTRUDER|default(printer.extruder.target)|float %}
    {% set CHAMBER_TEMP = params.CHAMBER|default(0)|float %}
    {% set FILAMENT_TYPE = params.FILAMENT_TYPE|default(printer.save_variables.variables.filament_type)|float %}

    {% set COLORS = params.COLORS|default("")|string %}
    {% set colors_array = COLORS.split(",") %}
    {% set ttg_map = printer.mmu.ttg_map %}
    
    
    {% set BED_OFFSET = printer.heater_bed.target - BED_TEMP %}
	{% set EXTRUDER_OFFSET = printer.extruder.target - EXTRUDER_TEMP %}
	#SAVE_VARIABLE VARIABLE=CHAMBER_SET_TEMP VALUE={s}
	{% if printer.save_variables.variables.chamber_set_temp == 0 %}
	    {% set CHAMBER_OFFSET = 0 %}
	{% else %}
	    {% set CHAMBER_OFFSET = printer.save_variables.variables.chamber_set_temp - CHAMBER_TEMP %}
	{% endif %}
	
	{% for color in colors_array %}
        {% set tool = loop.index0 %}
        {% set gate = ttg_map[tool] %}                  # Make sure map to correct gate in case of TTG map
        {% set fixed_color = color.replace('\x23', '') %}
        MMU_GATE_MAP GATE={gate} COLOR={fixed_color}          # Register the filament color against correct gate in gate map
    {% endfor %}
    

I can, and probably will try calling MMU_START_SETUP macro from the print_start macro post minipulation

Additional context
it would be nice to be able to call the array instead of having to list each individual tool TOOL_COLORS={filament_colour[0]},{filament_colour[1]},{filament_colour[2]},{filament_colour[3]},{filament_colour[4]},{filament_colour[5]},{filament_colour[6]},{filament_colour[7]},{filament_colour[8]},{filament_colour[9]},{filament_colour[10]},{filament_colour[11]}` like what is seen at the end of the gcode file. `; filament_colour = #101820;#F0F0F0;#DE4343;#FF6A13;#FFC845;#3A913F;#002677;#6E3FA3;#FFC845;#6C6D71;#F59BBB;#5BC2E7 ; filament_cooling_final_speed = 3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4,3.4 ; filament_cooling_initial_speed = 2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2 ; filament_cooling_moves = 4,4,4,4,4,4,4,4,4,4,4,4 ; filament_cooling_zone_pause = 0,0,0,0,0,0,0,0,0,0,0,0 ; filament_cost = 22,77.3,22,22,22,22,22,22,22,22,22,22 ; filament_custom_variables = ;;;;;;;;;;;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant