Skip to content

rjduran/bambu-gcode-reference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Bambu G-code Reference

This document contains a table of all the G-codes and M-codes that Bambu Studio (Marlin/Legacy mode) generates, including Bambu-specific codes. Each entry includes the code and a brief description of its purpose. This is very much a work in progress and is being done for the purpose of learning how to better understand the machine code generated by Bambu Studio.

Why I created this reference document

I started this repo because I couldn't locate a reliable enough source for this documentation and it appears Bambu Lab has no interest in creating such documentation. The Bambu Lab Community Forum is the next most reliable source of information when it comes to reading, writing, and learning to modify gcode for Bambu Lab machines. Any relevant posts are linked in the References. If you have knowledge to contribute to this repo, submit a pull request.

Table of Contents


Header Comments

The metadata found in the top 400+ lines of any file generated by Bambu Studio consists of values used by Bambu Studio and ignored by the printer during execution. Each line begins with a semicolon ; to indicate it's a comment in gcode.

What are header comments and what are they used for?

  • They are not parsed by Marlin firmware or used in motion/temperature control.
  • The actual print moves and temperatures are controlled only by G/M-codes.
  • The printer ignores all comments during runtime execution.
  • Bambu Studio uses the header comments. How each comment is used is still TBD.

Observations

  1. If you remove the header and config blocks form the gcode file, Bambu Studio will crash.
  2. If you include the header block only, you get an error and the toolpath doesn't load. The app does not crash.
  3. Any of the comments in the header that start with ; printer_ have something to do with how the file is rendered in Bambu studio.
  4. If you remove the data from the following lines, the code still opens in Bambu studio.
    • ; machine_start_gcode =
    • ; machine_end_gcode =
    • ; layer_change_gcode =
    • ; time_lapse_gcode =
    • ; change_filament_gcode =

List of Comments

Line Comment Value Type Purpose
1 ; HEADER_BLOCK_START Header block start
2 ; BambuStudio 02.00.01.50 Version of Bambu Studio that generated this file
3 ; model printing time 21s How long it takes to print
4 ; total estimated time 6m 39s Total estimated job time
5 ; total layer number 3 int Number of layers
6 ; total filament length [mm] 35.16 float Total filament used
7 ; total filament volume [cm^3] 84.58 float Total filament volume
8 ; total filament weight [g] 0.11 float Total filament weight
9 ; filament_density 1.26 float Filament density
10 ; filament_diameter 1.75 float Filament diameter
11 ; max_z_height 0.6 float Maximum layer height of job
12 ; HEADER_BLOCK_END Header block end
14 ; CONFIG_BLOCK_START Config block start
15 ; accel_to_decel_enable 0 int
16 ; accel_to_decel_factor 50%
17 ; activate_air_filtration 0 int
18 ; additional_cooling_fan_speed 70 int
19 ; apply_scarf_seam_on_circles 1 int
20 ; auxiliary_fan 1 int
21 ; bed_custom_model
22 ; bed_custom_texture
23 ; bed_exclude_area 0x0,18x0,18x28,0x28
24 ; bed_temperature_formula by_first_filament
25 ; before_layer_change_gcode
26 ; best_object_pos 0.5,0.5
27 ; bottom_color_penetration_layers 3 int
28 ; bottom_shell_layers 0 int
29 ; bottom_shell_thickness 0 int
30 ; bottom_surface_pattern monotonic
31 ; bridge_angle 0 int
32 ; bridge_flow 1 int
33 ; bridge_no_support 0 int
34 ; bridge_speed 50 int
35 ; brim_object_gap 0.1 float
36 ; brim_type auto_brim
37 ; brim_width 5 int
38 ; chamber_temperatures 0 int
39 ; change_filament_gcode
40 ; circle_compensation_manual_offset 0 int
41 ; circle_compensation_speed 200 int
42 ; close_fan_the_first_x_layers 1 int
43 ; complete_print_exhaust_fan_speed 70 int
44 ; cool_plate_temp 35 int
45 ; cool_plate_temp_initial_layer 35 int
46 ; counter_coef_1 0 int
47 ; counter_coef_2 0.008 float
48 ; counter_coef_3 -0.041 float
49 ; counter_limit_max 0.033 float
50 ; counter_limit_min -0.035 float
51 ; curr_bed_type Textured PEI Plate
52 ; default_acceleration 10000 int
53 ; default_filament_colour ""
54 ; default_filament_profile "Bambu PLA Basic @BBL X1C"
55 ; default_jerk 0 int
56 ; default_nozzle_volume_type Standard
57 ; default_print_profile 0.20mm Standard @BBL X1C
58 ; deretraction_speed 30 int
59 ; detect_floating_vertical_shell 1 int
60 ; detect_narrow_internal_solid_infill 1 int
61 ; detect_overhang_wall 1 int
62 ; detect_thin_wall 0 int
63 ; diameter_limit 50 int
64 ; different_settings_to_system
65 ; draft_shield disabled
66 ; during_print_exhaust_fan_speed 70 int
67 ; elefant_foot_compensation 0 int
68 ; enable_arc_fitting 1 int
69 ; enable_circle_compensation 0 int
70 ; enable_long_retraction_when_cut 2 int
71 ; enable_overhang_bridge_fan 1 int
72 ; enable_overhang_speed 1 int
73 ; enable_pre_heating 0 int
74 ; enable_pressure_advance 0 int
75 ; enable_prime_tower 0 int
76 ; enable_support 0 int
77 ; enforce_support_layers 0 int
78 ; eng_plate_temp 0 int
79 ; eng_plate_temp_initial_layer 0 int
80 ; ensure_vertical_shell_thickness enabled
81 ; exclude_object 1 int
82 ; extruder_ams_count 1#0|4#0;
83 ; extruder_clearance_dist_to_rod 33 int
84 ; extruder_clearance_height_to_lid 90 int
85 ; extruder_clearance_height_to_rod 34 int
86 ; extruder_clearance_max_radius 68 int
87 ; extruder_colour #018001
88 ; extruder_offset 0x2
89 ; extruder_printable_area
90 ; extruder_type Direct Drive
91 ; extruder_variant_list "Direct Drive Standard"
92 ; fan_cooling_layer_time 100 int
93 ; fan_max_speed 100 int
94 ; fan_min_speed 100 int
95 ; filament_adhesiveness_category 100 int
96 ; filament_change_length 5 int
97 ; filament_colour #00AE42
98 ; filament_cost 24.99 float
99 ; filament_density 1.26 float
100 ; filament_diameter 1.75 float
101 ; filament_end_gcode "; filament end gcode \n\n"
102 ; filament_extruder_variant "Direct Drive Standard"
103 ; filament_flow_ratio 0.98 float
104 ; filament_ids GFA00
105 ; filament_is_support 0 int
106 ; filament_long_retractions_when_cut 1 int
107 ; filament_map 1 int
108 ; filament_map_mode Auto For Flush
109 ; filament_max_volumetric_speed 21 int
110 ; filament_minimal_purge_on_wipe_tower 15 int
111 ; filament_notes
112 ; filament_pre_cooling_temperature 0 int
113 ; filament_prime_volume 30 int
114 ; filament_ramming_travel_time 0 int
115 ; filament_ramming_volumetric_speed -1 int
116 ; filament_retraction_distances_when_cut 18 int
117 ; filament_scarf_gap 0 int
118 ; filament_scarf_height 0.1 float
119 ; filament_scarf_length 10 int
120 ; filament_scarf_seam_type none
121 ; filament_self_index 1 int
122 ; filament_settings_id "Bambu PLA Basic @BBL X1C"
123 ; filament_shrink 1 int
124 ; filament_soluble 0 int
125 ; filament_start_gcode
126 ; filament_type PLA
127 ; filament_vendor "Bambu Lab"
128 ; filename_format {input_filename_base}{filament_type[0]}{print_time}.gcode
129 ; filter_out_gap_fill 0 int
130 ; first_layer_print_sequence 0 int
131 ; flush_into_infill 0 int
132 ; flush_into_objects 0 int
133 ; flush_into_support 1 int
134 ; flush_multiplier 1 int
135 ; flush_volumes_matrix 0 int
136 ; flush_volumes_vector 140,140
137 ; full_fan_speed_layer 0 int
138 ; fuzzy_skin none
139 ; fuzzy_skin_point_distance 0.8 float
140 ; fuzzy_skin_thickness 0.3 float
141 ; gap_infill_speed 250 int
142 ; gcode_add_line_number 0 int
143 ; gcode_flavor marlin
144 ; grab_length 0 int
145 ; has_scarf_joint_seam 1 int
146 ; head_wrap_detect_zone
147 ; hole_coef_1 0 int
148 ; hole_coef_2 -0.008 float
149 ; hole_coef_3 0.23415 float
150 ; hole_limit_max 0.22 float
151 ; hole_limit_min 0.088 float
152 ; host_type octoprint
153 ; hot_plate_temp 55 int
154 ; hot_plate_temp_initial_layer 55 int
155 ; hotend_cooling_rate 2 int
156 ; hotend_heating_rate 2 int
157 ; impact_strength_z 13.8 float
158 ; independent_support_layer_height 1 int
159 ; infill_combination 0 int
160 ; infill_direction 45 int
161 ; infill_jerk 9 int
162 ; infill_rotate_step 0 int
163 ; infill_shift_step 0.4 float
164 ; infill_wall_overlap 0.15 float
165 ; initial_layer_acceleration 500 int
166 ; initial_layer_flow_ratio 1 int
167 ; initial_layer_infill_speed 105 int
168 ; initial_layer_jerk 9 int
169 ; initial_layer_line_width 0.5 float
170 ; initial_layer_print_height 0.2 float
171 ; initial_layer_speed 50 int
172 ; initial_layer_travel_acceleration 6000 int
173 ; inner_wall_acceleration 0 int
174 ; inner_wall_jerk 9 int
175 ; inner_wall_line_width 0.45 float
176 ; inner_wall_speed 300 int
177 ; interface_shells 0 int
178 ; interlocking_beam 0 int
179 ; interlocking_beam_layer_count 2 int
180 ; interlocking_beam_width 0.8 float
181 ; interlocking_boundary_avoidance 2 int
182 ; interlocking_depth 2 int
183 ; interlocking_orientation 22.5 float
184 ; internal_bridge_support_thickness 0.8 float
185 ; internal_solid_infill_line_width 0.42 float
186 ; internal_solid_infill_pattern zig-zag
187 ; internal_solid_infill_speed 250 int
188 ; ironing_direction 45 int
189 ; ironing_flow 0.1 float
190 ; ironing_inset 0.21 float
191 ; ironing_pattern zig-zag
192 ; ironing_spacing 0.15 float
193 ; ironing_speed 30 int
194 ; ironing_type no ironing
195 ; is_infill_first 0 int
196 ; layer_change_gcode
197 ; layer_height 0.2 float
198 ; line_width 0.42 float
199 ; long_retractions_when_cut 0 int
200 ; machine_end_gcode
201 ; machine_load_filament_time 29 int
202 ; machine_max_acceleration_e 5000,5000
203 ; machine_max_acceleration_extruding 20000,20000
204 ; machine_max_acceleration_retracting 5000,5000
205 ; machine_max_acceleration_travel 9000,9000
206 ; machine_max_acceleration_x 20000,20000
207 ; machine_max_acceleration_y 20000,20000
208 ; machine_max_acceleration_z 500,200
209 ; machine_max_jerk_e 2.5,2.5
210 ; machine_max_jerk_x 9,9
211 ; machine_max_jerk_y 9,9
212 ; machine_max_jerk_z 3,3
213 ; machine_max_speed_e 30,30
214 ; machine_max_speed_x 500,200
215 ; machine_max_speed_y 500,200
216 ; machine_max_speed_z 20,20
217 ; machine_min_extruding_rate 0,0
218 ; machine_min_travel_rate 0,0
219 ; machine_pause_gcode M400 U1
220 ; machine_start_gcode
221 ; machine_switch_extruder_time 0 int
222 ; machine_unload_filament_time 28 int
223 ; master_extruder_id 1 int
224 ; max_bridge_length 0 int
225 ; max_layer_height 0.28 float
226 ; max_travel_detour_distance 0 int
227 ; min_bead_width 0.85 float
228 ; min_feature_size 0.25 float
229 ; min_layer_height 0.08 float
230 ; minimum_sparse_infill_area 15 int
231 ; mmu_segmented_region_interlocking_depth 0 int
232 ; mmu_segmented_region_max_width 0 int
233 ; nozzle_diameter 0.4 float
234 ; nozzle_height 4.2 float
235 ; nozzle_temperature 220 int
236 ; nozzle_temperature_initial_layer 220 int
237 ; nozzle_temperature_range_high 240 int
238 ; nozzle_temperature_range_low 190 int
239 ; nozzle_type stainless_steel
240 ; nozzle_volume 107 int
241 ; nozzle_volume_type Standard
242 ; only_one_wall_first_layer 0 int
243 ; ooze_prevention 0 int
244 ; other_layers_print_sequence 0 int
245 ; other_layers_print_sequence_nums 0 int
246 ; outer_wall_acceleration 5000 int
247 ; outer_wall_jerk 9 int
248 ; outer_wall_line_width 0.42 float
249 ; outer_wall_speed 200 int
250 ; overhang_1_4_speed 0 int
251 ; overhang_2_4_speed 50 int
252 ; overhang_3_4_speed 30 int
253 ; overhang_4_4_speed 10 int
254 ; overhang_fan_speed 100 int
255 ; overhang_fan_threshold 0.5 float
256 ; overhang_threshold_participating_cooling 0.95 float
257 ; overhang_totally_speed 10 int
258 ; physical_extruder_map 0 int
259 ; post_process
260 ; pre_start_fan_time 2 int
261 ; precise_z_height 0 int
262 ; pressure_advance 0.02 float
263 ; prime_tower_brim_width 3 int
264 ; prime_tower_enable_framework 0 int
265 ; prime_tower_extra_rib_length 0 int
266 ; prime_tower_fillet_wall 1 int
267 ; prime_tower_infill_gap 1.5 float
268 ; prime_tower_lift_height -1 int
269 ; prime_tower_lift_speed 90 int
270 ; prime_tower_max_speed 90 int
271 ; prime_tower_rib_wall 1 int
272 ; prime_tower_rib_width 8 int
273 ; prime_tower_skip_points 1 int
274 ; prime_tower_width 35 int
275 ; print_compatible_printers
276 ; print_extruder_id 1 int
277 ; print_extruder_variant "Direct Drive Standard"
278 ; print_flow_ratio 1 int
279 ; print_sequence by layer
280 ; print_settings_id 0.20mm Standard @BBL X1C
281 ; printable_area 0x0,256x0,256x256,0x256
282 ; printable_height 250 int
283 ; printer_extruder_id 1 int
284 ; printer_extruder_variant "Direct Drive Standard"
285 ; printer_model Bambu Lab P1S
286 ; printer_notes
287 ; printer_settings_id Bambu Lab P1S 0.4 nozzle
288 ; printer_structure corexy
289 ; printer_technology FFF
290 ; printer_variant 0.4 float
291 ; printhost_authorization_type key
292 ; printhost_ssl_ignore_revoke 0 int
293 ; printing_by_object_gcode
294 ; process_notes
295 ; raft_contact_distance 0.1 float
296 ; raft_expansion 1.5 float
297 ; raft_first_layer_density 0.9 float
298 ; raft_first_layer_expansion 2 int
299 ; raft_layers 0 int
300 ; reduce_crossing_wall 0 int
301 ; reduce_fan_stop_start_freq 1 int
302 ; reduce_infill_retraction 1 int
303 ; required_nozzle_HRC 3 int
304 ; resolution 0.012 float
305 ; retract_before_wipe 0 int
306 ; retract_length_toolchange 2 int
307 ; retract_lift_above 0 int
308 ; retract_lift_below 249 int
309 ; retract_restart_extra 0 int
310 ; retract_restart_extra_toolchange 0 int
311 ; retract_when_changing_layer 1 int
312 ; retraction_distances_when_cut 18 int
313 ; retraction_length 0.8 float
314 ; retraction_minimum_travel 1 int
315 ; retraction_speed 30 int
316 ; role_base_wipe_speed 1 int
317 ; scan_first_layer 0 int
318 ; scarf_angle_threshold 155 int
319 ; seam_gap 0.15 float
320 ; seam_position aligned
321 ; seam_slope_conditional 1 int
322 ; seam_slope_entire_loop 0 int
323 ; seam_slope_inner_walls 1 int
324 ; seam_slope_steps 10 int
325 ; silent_mode 0 int
326 ; single_extruder_multi_material 1 int
327 ; skirt_distance 2 int
328 ; skirt_height 1 int
329 ; skirt_loops 0 int
330 ; slice_closing_radius 0.049 float
331 ; slicing_mode regular
332 ; slow_down_for_layer_cooling 1 int
333 ; slow_down_layer_time 4 int
334 ; slow_down_min_speed 20 int
335 ; small_perimeter_speed 0.5 float
336 ; small_perimeter_threshold 0 int
337 ; smooth_coefficient 150 int
338 ; smooth_speed_discontinuity_area 1 int
339 ; solid_infill_filament 1 int
340 ; sparse_infill_acceleration 1 int
341 ; sparse_infill_anchor 4 int
342 ; sparse_infill_anchor_max 20 int
343 ; sparse_infill_density 0 int
344 ; sparse_infill_filament 1 int
345 ; sparse_infill_line_width 0.45 float
346 ; sparse_infill_pattern grid
347 ; sparse_infill_speed 270 int
348 ; spiral_mode 0 int
349 ; spiral_mode_max_xy_smoothing 2 int
350 ; spiral_mode_smooth 0 int
351 ; standby_temperature_delta -5 int
352 ; start_end_points 30x-3,54x245
353 ; supertack_plate_temp 45 int
354 ; supertack_plate_temp_initial_layer 45 int
355 ; support_air_filtration 0 int
356 ; support_angle 0 int
357 ; support_base_pattern default
358 ; support_base_pattern_spacing 2.5 float
359 ; support_bottom_interface_spacing 0.5 float
360 ; support_bottom_z_distance 0.2 float
361 ; support_chamber_temp_control 0 int
362 ; support_critical_regions_only 0 int
363 ; support_expansion 0 int
364 ; support_filament 0 int
365 ; support_interface_bottom_layers 2 int
366 ; support_interface_filament 0 int
367 ; support_interface_loop_pattern 0 int
368 ; support_interface_not_for_body 1 int
369 ; support_interface_pattern auto
370 ; support_interface_spacing 0.5 float
371 ; support_interface_speed 80 int
372 ; support_interface_top_layers 2 int
373 ; support_line_width 0.42 float
374 ; support_object_first_layer_gap 0.2 float
375 ; support_object_xy_distance 0.35 float
376 ; support_on_build_plate_only 0 int
377 ; support_remove_small_overhang 1 int
378 ; support_speed 150 int
379 ; support_style default
380 ; support_threshold_angle 30 int
381 ; support_top_z_distance 0.2 float
382 ; support_type tree(auto)
383 ; symmetric_infill_y_axis 0 int
384 ; temperature_vitrification 45 int
385 ; template_custom_gcode
386 ; textured_plate_temp 55 int
387 ; textured_plate_temp_initial_layer 55 int
388 ; thick_bridges 0 int
389 ; thumbnail_size 50x50
390 ; time_lapse_gcode
391 ; timelapse_type 0 int
392 ; top_area_threshold 2 int
393 ; top_color_penetration_layers 5 int
394 ; top_one_wall_type all top
395 ; top_shell_layers 0 int
396 ; top_shell_thickness 1 int
397 ; top_solid_infill_flow_ratio 1 int
398 ; top_surface_acceleration 2000 int
399 ; top_surface_jerk 9 int
400 ; top_surface_line_width 0.42 float
401 ; top_surface_pattern monotonicline
402 ; top_surface_speed 200 int
403 ; travel_acceleration 10000 int
404 ; travel_jerk 9 int
405 ; travel_speed 500 int
406 ; travel_speed_z 0 int
407 ; tree_support_branch_angle 45 int
408 ; tree_support_branch_diameter 2 int
409 ; tree_support_branch_diameter_angle 5 int
410 ; tree_support_branch_distance 5 int
411 ; tree_support_wall_count 0 int
412 ; unprintable_filament_types ""
413 ; upward_compatible_machine
414 ; use_firmware_retraction 0 int
415 ; use_relative_e_distances 1 int
416 ; vertical_shell_speed 0.8 float
417 ; wall_distribution_count 1 int
418 ; wall_filament 1 int
419 ; wall_generator classic
420 ; wall_loops 1 int
421 ; wall_sequence inner wall/outer wall
422 ; wall_transition_angle 10 int
423 ; wall_transition_filter_deviation 0.25 float
424 ; wall_transition_length 1 int
425 ; wipe 1 int
426 ; wipe_distance 2 int
427 ; wipe_speed 0.8 float
428 ; wipe_tower_no_sparse_layers 0 int
429 ; wipe_tower_rotation_angle 0 int
430 ; wipe_tower_x 165 int
431 ; wipe_tower_y 250 int
432 ; xy_contour_compensation 0 int
433 ; xy_hole_compensation 0 int
434 ; z_direction_outwall_speed_continuous 0 int
435 ; z_hop 0.4 float
436 ; z_hop_types Auto Lift
437 ; CONFIG_BLOCK_END

Standard Marlin G-codes

Code Description
G0 Rapid linear move (X, Y, Z)
G1 Controlled linear move (used for printing and travel)
G5 B-spline curve move (not standard in Marlin; may be ignored)
G28 Auto home all axes. Moves all axes to their endstops (zero position).
G90 Set to absolute positioning (most common mode).
G91 Set to relative positioning (rare, used for manual adjustments).
G92 Set current position (e.g., G92 E0 resets extruder position)

Standard Marlin M-codes

Code Description
M17 Enable all stepper motors
M82 Set extruder to absolute mode
M83 Set extruder to relative mode
M104 Snnn Set hotend temperature (non-blocking)
M109 Snnn Set hotend temperature and wait until target reached
M140 Set bed temperature (non-blocking)
M190 Set bed temperature and wait
M106 Set fan speed (eg. M106 S255)
M107 Turn fan off
M201 Set max acceleration for axes (X, Y, Z, E)
M203 Set max feedrate for axes
M204 Set default acceleration (P for print, T for travel)
M205 Advanced settings (minimum feedrate, jerk, etc.)
M220 Snnn Set speed override (print speed as percentage) (eg. M220 S100 ;Reset Feedrate)
M221 Snnn Set flow override (extrusion flow percentage) (eg. M221 S100 ;Reset Flowrate)
M400 Wait for all movements to finish
M900 Set Linear Advance (K-factor)
M84 Disable stepper motors

Bambu-Specific G-codes

Code Description
M142 firmware reference (XC1?), Aux fan, chamber temp, set fan speed (eg. M142 P1 R35 S40)

Bambu-Specific M-codes

Code Description
M73 Set build progress and remaining time (used for display/preview)
M1001 Start of print metadata block (job ID, print name, etc.)
M1002 End of print metadata block (job status, logs)
M1003 Custom bed leveling (Bambu's version of mesh calibration)
M1004 AMS / filament path selection or control
M1005 Unknown – likely print status or internal state logging
M1010 AMS info block (e.g., filament type, color, location)
M104 T0 Sxxx Hn Bambu version of M104 with heating override or flags
M109 T0 Sxxx Hn Bambu version of M109 (wait for hotend) with control hint
M140 Sxxx Hn Bambu-specific bed temp set with heating hint
M190 Sxxx Hn Wait for bed temp (Bambu version with override)
M2000 Set material tuning parameters (e.g., retraction, flow)
M2001 Set filament flow rate tuning
M2002 Set acceleration/jerk parameters
M2003 Set cooling fan tuning or behavior
M2004–M2010 Misc tuning parameters (pressure advance, min/max flow, etc.)
M220 B1 Speed override with Bambu-specific override flag B1
M221 B1 Flow override with Bambu-specific override flag B1
T0 / T1 Tool/filament selection (can trigger AMS actions on Bambu)

References


Last updated: April 2025

About

Bambu Lab G-Code Reference

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages