G-Code output file name format to include Used Filament in meters & grams
Sorry if this information already exists elsewhere, but I couldn't find it in any online forums...
The following script entered in "Print Settings/Output options/Output Format Filename" will add the amount of Used Filament in both meters (m) and grams (g) to the G-Code Output Filename:
{input_filename_base}_{print_time}_{digits(used_filament,1,2)}m_{digits(used_filament*3.1415626*filament_diameter[0]*filament_diameter[0]/4*filament_density[0],1,2)}g_{digits(layer_height,1,2)}mm_{temperature[0]}C_{filament_type[0]}_{printer_model}.gcode
(Note: Results verified for PrusaSlicer Version: 2.8.1+win64)
RE: G-Code output file name format to include Used Filament in meters & grams
Output format placeholders are listed on the knowledge base here https://help.prusa3d.com/article/list-of-placeholders_205643#output-filename-format-fdm
and macro's for adjusting them such as decimal places etc are listed here https://help.prusa3d.com/article/macros_1775
Theres also the old ways that predate the newer added functions such as digits or round etc which you can read about in a previous thread in this forum https://forum.prusa3d.com/forum/prusaslicer/howto-round-file-output-name-placeholder-total_cost/
RE: G-Code output file name format to include Used Filament in meters & grams
Thanks @neophyl. I guess I had found the "used_filament" placeholder in the list you referenced above. It was not clear from that documentation however what units are output. It turns out to be length in meters as the default.
I couldn't figure out if there was a way to specify another unit with placeholder indexing or not, so I decided to get creative with mass. It is a relatively easy matter to calculate used filament mass in grams as (length) x (area) x (mass density). We already have (length) = "used_filament" in meters. We can calculate (area) as (Pi/4) x "filament_diameter[0]" in mm_squared. [Note that I could not find a placeholder for mathematical constant Pi either, and it appears I entered it incorrectly above... it should have been 3.141592654 out to nine significant digits... oops!]. That leaves (mass density) = "filament_density" in gram/cm_cubed. It turns out that 1 cm_cubed = 1000 mm_cubed so the final units are correctly output in grams.
It is very important to enter the correct parameters for the filament being used in the Prusa software under "Filaments/Filament/Diameter and Filaments/Filament/Density". The filename values should then match those listed under sliced info.