Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save zekrom-vale/0496e1ca05b54fe22d3990752e24b052 to your computer and use it in GitHub Desktop.

Select an option

Save zekrom-vale/0496e1ca05b54fe22d3990752e24b052 to your computer and use it in GitHub Desktop.
Adds medadata details for Kobra 3 printers
{
"align_infill_direction_to_model": "1",
"enable_support": "1",
"ensure_vertical_shell_thickness": "ensure_critical_only",
"exclude_object": "1",
"flush_into_infill": "1",
"from": "User",
"hole_to_polyhole": "1",
"infill_combination": "1",
"inherits": "0.20mm Standard @Anycubic Kobra 3 0.4 nozzle",
"is_custom_defined": "0",
"max_travel_detour_distance": "25%",
"name": "0.20mm Master @Anycubic Kobra 3 0.4 nozzle",
"notes": "",
"overhang_reverse": "1",
"post_process": [
"python3 /home/zekrom/k3_fix.py"
],
"print_settings_id": "0.20mm Master @Anycubic Kobra 3 0.4 nozzle",
"solid_infill_rotate_template": "45, 135",
"sparse_infill_density": "10%",
"sparse_infill_pattern": "gyroid",
"staggered_inner_seams": "1",
"support_style": "snug",
"support_type": "normal(auto)",
"version": "2.3.1.10",
"wall_generator": "arachne",
"wall_loops": "3",
"wipe_before_external_loop": "1",
"wipe_on_loops": "1",
"wipe_tower_no_sparse_layers": "1"
}
{
"adaptive_bed_mesh_margin": "0",
"auxiliary_fan": "0",
"bbl_use_printhost": "0",
"bed_custom_model": "",
"bed_custom_texture": "",
"bed_exclude_area": [],
"bed_mesh_max": "0,0",
"bed_mesh_min": "0,0",
"bed_mesh_probe_distance": "0,0",
"before_layer_change_gcode": "; BEFORE_LAYER_CHANGE [layer_num] @ [layer_z]mm",
"best_object_pos": "0.5,0.5",
"change_extrusion_role_gcode": "",
"change_filament_gcode": "",
"cooling_tube_length": "0",
"cooling_tube_retraction": "0",
"default_bed_type": "",
"default_filament_profile": [
"Anycubic PLA @Anycubic Kobra 3 0.4 nozzle"
],
"default_print_profile": "0.16mm Optimal @Anycubic Kobra 3 0.4 nozzle",
"deretraction_speed": [
"60"
],
"disable_m73": "1",
"emit_machine_limits_to_gcode": "1",
"enable_filament_ramming": "0",
"enable_long_retraction_when_cut": "0",
"extra_loading_move": "0",
"extruder_clearance_height_to_lid": "200",
"extruder_clearance_height_to_rod": "30",
"extruder_clearance_radius": "130",
"extruder_colour": [
"#FF4D4F"
],
"extruder_offset": [
"0x0"
],
"fan_kickstart": "0",
"fan_speedup_overhangs": "1",
"fan_speedup_time": "0",
"from": "User",
"gcode_flavor": "klipper",
"head_wrap_detect_zone": [],
"high_current_on_filament_swap": "0",
"host_type": "octoprint",
"inherits": "Anycubic Kobra 3 0.4 nozzle",
"is_custom_defined": "0",
"layer_change_gcode": "; AFTER_LAYER_CHANGE [layer_num] @ [layer_z]mm",
"long_retractions_when_cut": [
"0"
],
"machine_end_gcode": "M400\nG92 E0 ; zero the extruder\nG1 E-2 F3600\n{if max_layer_z < max_print_height-1}G1 Z{max_layer_z+2} F900 ; Move print head further up{endif}\nG1 X250 Y220 F12000 ; present print\nM140 S0 ; turn off heatbed\nM104 S0 ; turn off temperature\nM107;turn off fan\nM84; disable stepper motors",
"machine_load_filament_time": "42",
"machine_max_acceleration_e": [
"20000",
"20000"
],
"machine_max_acceleration_extruding": [
"20000",
"20000"
],
"machine_max_acceleration_retracting": [
"20000",
"20000"
],
"machine_max_acceleration_travel": [
"20000",
"20000"
],
"machine_max_acceleration_x": [
"15000",
"15000"
],
"machine_max_acceleration_y": [
"15000",
"15000"
],
"machine_max_acceleration_z": [
"5000",
"5000"
],
"machine_max_jerk_e": [
"10",
"10"
],
"machine_max_jerk_x": [
"20",
"20"
],
"machine_max_jerk_y": [
"20",
"20"
],
"machine_max_jerk_z": [
"5",
"5"
],
"machine_max_junction_deviation": [
"0",
"0"
],
"machine_max_speed_e": [
"80",
"80"
],
"machine_max_speed_x": [
"600",
"600"
],
"machine_max_speed_y": [
"600",
"600"
],
"machine_max_speed_z": [
"10",
"10"
],
"machine_min_extruding_rate": [
"0",
"0"
],
"machine_min_travel_rate": [
"0",
"0"
],
"machine_pause_gcode": "M601",
"machine_start_gcode": "G9111 bedTemp=[first_layer_bed_temperature] extruderTemp=[first_layer_temperature[initial_tool]]\nM117\nM900 K0.051",
"machine_tool_change_time": "0",
"machine_unload_filament_time": "0",
"manual_filament_change": "0",
"max_layer_height": [
"0.28"
],
"max_resonance_avoidance_speed": "120",
"min_layer_height": [
"0.08"
],
"min_resonance_avoidance_speed": "70",
"name": "Anycubic Kobra 3 0.4 nozzle - Master",
"nozzle_diameter": [
"0.4"
],
"nozzle_height": "4",
"nozzle_hrc": "0",
"nozzle_type": "brass",
"nozzle_volume": "58.7795",
"parking_pos_retraction": "0",
"pellet_modded_printer": "0",
"preferred_orientation": "0",
"printable_area": [
"0x0",
"255x0",
"255x255",
"0x255"
],
"printable_height": "260",
"printer_model": "Anycubic Kobra 3",
"printer_notes": "",
"printer_settings_id": "Anycubic Kobra 3 0.4 nozzle - Master",
"printer_structure": "i3",
"printer_technology": "FFF",
"printer_variant": "0.4",
"printhost_authorization_type": "key",
"printhost_ssl_ignore_revoke": "0",
"printing_by_object_gcode": "",
"purge_in_prime_tower": "0",
"resonance_avoidance": "0",
"retract_before_wipe": [
"0%"
],
"retract_length_toolchange": [
"0"
],
"retract_lift_above": [
"0.3"
],
"retract_lift_below": [
"259.6"
],
"retract_lift_enforce": [
"All Surfaces"
],
"retract_restart_extra": [
"0"
],
"retract_restart_extra_toolchange": [
"0"
],
"retract_when_changing_layer": [
"1"
],
"retraction_distances_when_cut": [
"18"
],
"retraction_length": [
"1"
],
"retraction_minimum_travel": [
"1"
],
"retraction_speed": [
"60"
],
"scan_first_layer": "0",
"silent_mode": "0",
"single_extruder_multi_material": "1",
"support_air_filtration": "1",
"support_chamber_temp_control": "1",
"support_multi_bed_types": "0",
"template_custom_gcode": "",
"thumbnails": "230x110/PNG, 512x512/PNG",
"thumbnails_format": "PNG",
"time_cost": "0",
"time_lapse_gcode": "",
"travel_slope": [
"3"
],
"upward_compatible_machine": [],
"use_firmware_retraction": "0",
"use_relative_e_distances": "1",
"version": "2.3.1.10",
"wipe": [
"1"
],
"wipe_distance": [
"2"
],
"z_hop": [
"0.4"
],
"z_hop_types": [
"Auto Lift"
],
"z_offset": "0"
}
#!/usr/bin/env python3
"""
Anycubic Kobra 3 Post-Processing Script (OrcaSlicer Compatibility)
------------------------------------------------------------------
DESCRIPTION:
Fixes OrcaSlicer G-code for compatibility with Kobra 3 & ACE Pro:
1. Reconstructs the multi-material flush matrix for up to 8 filaments.
2. Injects model instance metadata required for the "Skip Object" UI.
3. Fixes thumbnail spacing and appends 'top' tag for the exclusion map.
4. Ensures compact JSON formatting to match Anycubic firmware expectations.
SETUP IN ORCASLICER:
1. Printer Settings -> Personnel -> Post-processing scripts:
python3 /home/path/to/file/k3_fix.py;
2. Printer Settings -> Basic Information -> G-code thumbnails:
230x110/PNG, 512x512/PNG
^ preview ^ exclusion map image displays at an odd angle
------------------------------------------------------------------
"""
import sys
import json
import os
import re
def hex_to_rgb(hex_str):
try:
hex_str = hex_str.lstrip('#')
return [int(hex_str[i:i+2], 16) for i in (0, 2, 4)]
except:
return [255, 255, 255]
def post_process(filename):
with open(filename, 'r') as f:
lines = f.readlines()
# --- 1. DYNAMIC DATA GATHERING ---
model_names = []
for line in lines:
match = re.search(r'EXCLUDE_OBJECT_DEFINE NAME=(.*?) ', line)
if match:
name = match.group(1).strip('"')
if name not in model_names:
model_names.append(name)
if not model_names:
model_names = ["Orca_Model"]
types_raw = os.environ.get('SLIC3R_FILAMENT_TYPE', '')
colors_raw = os.environ.get('SLIC3R_FILAMENT_COLOUR', '')
t_list = [t.strip() for t in types_raw.split(';') if t.strip()]
c_list = [c.strip() for c in colors_raw.split(';') if c.strip()]
N = len(t_list) if t_list else 1
raw_matrix = os.environ.get('SLIC3R_FLUSH_VOLUMES_MATRIX', '')
try:
m_vals = [float(x) for x in raw_matrix.split(',') if x.strip()]
except:
m_vals = []
matrix_final = m_vals if len(m_vals) == (N * N) else ([140.0] * (N * N))
vector_final = [140.0] * (N * 2)
# --- 2. JSON CONSTRUCTION (Compact) ---
source_info = {
"models": [{"file_source": 0, "mo_file_id": -1, "name": n} for n in model_names],
"models_from": 0, "plate_index": 1, "slice_paras_process": 1,
"software_version": "OrcaSlicer 2.3.1"
}
paint_info = []
for i in range(min(len(t_list), len(c_list))):
paint_info.append({"material_type": t_list[i], "paint_color": hex_to_rgb(c_list[i]), "paint_index": i})
proj_json = json.dumps({
"flush_multiplier": 1.0,
"flush_volumes_chan_multipliers": [1.0] * N,
"flush_volumes_matrix": matrix_final,
"flush_volumes_vector": vector_final
}, separators=(',', ':'))
paint_json = json.dumps(paint_info, separators=(',', ':'))
source_json = json.dumps(source_info, separators=(',', ':'))
# --- 3. RECONSTRUCTION WITH EXACT ORDER & CLEAN THUMBNAILS ---
forbidden = ('; project_info', '; paint_info', '; flush_multiplier',
'; exclude_object', '; test_mode', '; filament_colour_type',
'; model_instances', '; source_info')
clean_lines = [l for l in lines if not l.strip().startswith(forbidden)]
final_output = []
skip_next_empty = False
for i, line in enumerate(clean_lines):
# 1. Collapse Thumbnail Spacing
if line.startswith('; THUMBNAIL_BLOCK_START'):
final_output.append(line)
# Look ahead to skip the empty line and the lonely semicolon
skip_next_empty = True
continue
if skip_next_empty:
if line.strip() == "" or line.strip() == ";":
continue
else:
skip_next_empty = False # We hit the actual thumbnail begin
# 2. Inject 'top' tag for the Skip Object screen
if line.startswith('; thumbnail begin'):
parts = line.split()
if len(parts) >= 4 and parts[3] == '512x512' and 'top' not in line:
line = line.strip() + ' top\n'
# 3. Inject Metadata Block
if line.startswith('; HEADER_BLOCK_END'):
final_output.append(f'; exclude_object: 1\n')
final_output.append(f'; model_instances: {len(model_names)}\n')
final_output.append(f'; source_info: {source_json}\n')
final_output.append(f'; paint_info = {paint_json}\n')
final_output.append(f'; project_info = {proj_json}\n')
final_output.append('; flush_multiplier_calculate_by_acnext: 1\n')
final_output.append('; test_mode: 0\n')
final_output.append(line)
with open(filename, 'w') as f:
f.writelines(final_output)
if __name__ == "__main__":
if len(sys.argv) > 1:
post_process(sys.argv[-1])
@zekrom-vale
Copy link
Copy Markdown
Author

Paint info does not allow the printer to swap AMS feeds based on color, it may be for purging details. But it works fine with my Kobra 3. Exclusion map is a bit odd, but functional. Color testing is still needed. And I noticed that the GCODE does not purge enough on the start of the print, this is likely unrelated to the script and instead the config as it still occurs without this script.
P.S. Forks are welcome to fix issues or add features. All I want is Orca Slicer to be on par with ANycubic Slicer Next with compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment