All parameters in BambuStudio can be used as placeholders in custom GCode
As shown in the figure below, hover the mouse over the parameter to see the placeholder it uses.
Placeholder | type | meaning | example |
initial_tool | int 0-16 | Initial filament id |
;{if filament_type[initial_tool]=="PLA"}do_sth{endif} --use filament id to check the type of the filament, and do something if it is PLA |
initial_extruder | int 0-16 | Initial filament id |
;{if filament_type[initial_extruder]=="PLA"}do_sth{endif} --use filament id to check the type of the filament, and do something if it is PLA |
current_extruder | int 0-16 | Current filament |
M109 S{nozzle_temperature_initial_layer[current_extruder]} --set the nozzle temperature as the initial temperature the filament needed |
total_layer_count | int | Sum of the total layer |
; layer num/total_layer_count: {layer_num+1}/[total_layer_count] --display the total layer and current layer |
current_object_idx | int | Current object |
;{current_object_idx} --display the current object id |
has_wipe_tower | bool | Mark if there is a wipe tower or not |
{if !has_wipe_tower}do_sth{endif} -- if there is a wipe tower, do something |
total_toolchanges | int | Sum of filament changes times | {if total_toolchanges>10}do_sth{endif} |
print_bed_min | vector<float> | Bed area | If statement |
print_bed_max | vector<float> | Bed area | If statement |
print_bed_size | vector<float> | Bed area | If statement |
first_layer_print_convex_hull | vector<point> | The extruded convex hull of the first layer is used when leveling | |
first_layer_print_min | vector<float> | The print area of the first layer | If statement |
first_layer_print_max | vector<float> | The print area of the first layer | If statement |
first_layer_print_size | vector<float> | Size of the print area of the first layer | If statement |
bed_temperature_initial_layer | vector<int> | The bed temperature of the first layer |
M140 S{bed_temperature_initial_layer[current_extruder]} --Set the bed temperature of the first layer that the filament needed |
bed_temperature | vector<int> | Bed temperature |
M140 S{bed_temperature[current_extruder]} --Set the bed temperature of the first layer that the filament needed |
outer_wall_volumetric_speed | float | Volumetric speed of outer wall |
G0 X240 E15 F{outer_wall_volumetric_speed/(0.3*0.5) * 60} --calculate the outer wall speed according to the volumetric speed |
Placeholder | type | meaning | example |
previous_extruder | int 0-16 | Previous filament |
;{ filament_type[previous_extruder]} --get the type of the previous filament |
next_extruder | int 0-16 | Next filament |
;{ filament_type[next_extruder]} --get the type of the next filament |
layer_num | int | Current layer |
;{layer_num} --display the current layer num |
layer_z | float | Current print height |
G2 Z{layer_z+0.05} --the nozzle moves to layer_z+0.05 high |
max_layer_z | float | Max height of the printed object |
G1 Z{max_layer_z + 0.5} --the nozzle moves to max_layer_z+0.05 high |
toolchange_count | int | Filament change | {if toolchange_count > 1}\nG17\nG2 Z{max_layer_z + 0.4} I0.86 J0.86 P1 F10000 ; spiral lift a little from second lift\n{endif} |
old_retract_length | float | previous retract length |
G1 E-[old_retract_length] --retract |
new_retract_length | float | New retract length | G1 E-[new_retract_length] |
old_retract_length_toolchange | float | Retract the length of the new filament | G1 E-[old_retract_length_toolchange] |
new_retract_length_toolchange | float | Retract the length of the new filament | G1 E-[new_retract_length_toolchange] |
old_filament_temp | int | Temp of the previous filament | M104 S[old_filament_temp] |
new_filament_temp | int | Temp of new filament | M104 S[new_filament_temp] |
x_after_toolchange | float | Position after the filament change | G1 X[x_after_toolchange] Y[y_after_toolchange] Z[z_after_toolchange] F12000 |
y_after_toolchange | float | Position after the filament change | |
z_after_toolchange | float | Position after the filament change | |
first_flush_volume | float | Previous flush volume | If statement |
second_flush_volume | float | New flush volume | If statement |
old_filament_e_feedrate | int | Previous extrude speed |
G1 E23.7 F{old_filament_e_feedrate} --set the extrude speed of the old filament |
new_filament_e_feedrate | int | New extrude speed |
G1 E23.7 F{new_filament_e_feedrate} --set the extrude speed of the new filament |
flush_length_1 | float | Flush length of the 1st filament |
G1 E{(flush_length_1 - 23.7) * 0.02} F50 -- calculate the volumetric speed by flush length |
... | ... | ... | ... |
flush_length_16 | float | Flush length of the 16th filament | G1 E{(flush_length_16 - 23.7) * 0.02} F50 |
filament_extruder_id | int | The extruded filament id | If statement |
toolchange_z | float | The height when changing the filament |
G1 Z{toolchange_z} --move the extrude to the set height |
Placeholder | type | meaning | example |
layer_num | int | Layer number | {layer_num} |
layer_z | float | Layer height | G0 Z{layer_z+0.05} |
use {placeholder} could display the value of it
layer_z is the name of a placeholder, {layer_z} could get the value of layer_z |
Use placeholder[idex] to get the value of the array or vector
cool_plate_temp_initial_layer is an array cool_plate_temp_initial_layer[0] could get the value of the first element of cool_plate_temp_initial_layer {cool_plate_temp_initial_layer[0]} display the value of the it |
Conditional evaluation
{if scan_first_layer}\n;=========register first layer scan=====\nM977 S1 P60\n{endif} |
Ternary operator
(<condition> ? <cond_true>:<cond_false>) |
Gcode cmd
S{cool_plate_temp_initial_layer[0]} |
String, "string" means string type
Write: {"Bambu PLA Basic @BBL X1C" } Output: Bambu PLA Basic @BBL X1C |
Regex expression
/regex/ |
comparsion <, >, ==, !=, <>, <=, >=
toolchange_count > 1 |
logic &&, ||, !
{if old_filament_temp > 142 && next_extruder < 255};do_sth{endif} |
arithmetic +,-, *, /
{layer_num+1} Float is calculated to get float, and int is calculated to get int type. If you want the result to be a decimal, please add a float type parameter. For example,3/2=1 3.0/2=1.5 |
Regular expression matching
=~ matching !~not matching |
Strings are not parsed recursively
Write: {“[text in square brackets]”} Output: [text in square brackets] |
function
min(a,b) maximum max(a,b) minimum int(a) cast to int round(a) , for example, round(5.2)->5 digits(a num_digits,num_decimals=0) Rounding / padding with spaces: rounds fractional part to num_decimals digits (adding trailing zeros if needed), then left fills with spaces so the number has num_digits characters in total (including a decimal point if present). The last argument can be omitted and defaults to zero. zdigits(a,num_digits,num_decimals=0) same with digits(a) ,then left fills with 0 |