Hello there,
I was looking into the “Post-processing scripts” section of the “Others” tab setting.
I have read the placeholder list (Placeholder List | Bambu Lab Wiki) but it seems I cannot get it working. I would like to start with a script that changes the fan speed according to the layer height.
Thanks
In my testing the post processing scripts only gets invoked if you do file/export/gcode
What error are you getting?
I was trying to do a “fan tower” from Printables and using the provided gcode.
When I do export Gcode i get that the variable does not exist.
-
I do not have experience with post-processing g-code in a Bambu printer. I only test it with my s1pro with Klipper, yet it should be the same. In the post-processing scripts, you need to indicate the path to your scripts, which need to be interpreted by your system.
The error you got is related to writing the code in that section instead of using an external script. -
From what I understood, you don’t need the post-processing; if you go to your printer settings:
You will find a tab with the machine g-codes, which entail, for example, specific g-codes at layer change:
- Please be aware that this is an advanced use and requires careful decision-making. Also, Bambu Lab uses custom g-codes and thus does not rely purely on Marlin. Do it at your own risk.
- A safer but more time-consuming alternative consists of adding a custom g-code at different layers in the preview section:
Hi @JayZay,
thanks for the explanation. If I insert in the post processing script the path to the script, it does nothing. no error, same output. Also trying to insert the gcode elsewhere caused the error. According to the wiki some variables are not to be used in the filament section, but are global.
So no steps forward.
That’s rather than expected.
In which language are you writing the script? And which OS are you using?
I know these procedures are not well explained in the wiki, as I read it when trying to use it. You can find detailed information in the Slic3r manual or GitHub page.
It’s better to check if the issue is in the slicer or your script to debug your case. You can run the code directly, i.e., export your g-code without postprocessing. Then, run your script.
For example, I am using Python, so if I execute the following command:
> python mytestscrip.py mytestprint.gcode
It will result in the desired modified g-code file.
If the script works outside the slicer, you must add the path to the Python exe file followed by the script file path. E.g.:
“C:\Program Files\Python39\python.exe” D:\testpostprocessing.py;
Note that the " " is required if spaces exist in the path.
This is how I did it, and it worked at least for S1Pro; these commands may require some adaptations depending on your script language, interpreter, OS, etc…
If you put the wrong path I think you will also find you don’t get an error - because the only way to get the post processing script to run is when you select File/Export/Export G-Code. Just put any old value in the post-processing script field to verify this.
If you select File/Export/Export G-code you get an error message - but if you select print or export plate sliced file for example you don’t get the error message.
I am currently investigating how to get a script to run on the wifi send side of Bambu Studio - either but running something against the temporary file that it creates between slicing and sending, or perhaps modifying the actual software to run the post processing script.
That’s quite ambitious, especially regarding the sending part.
Wouldn’t it be easier to develop a script that adds the custom instruction within the slicer, making sensing or printing still possible?
If you need to change the software, requesting or working with the OrcaSlicer team is more reasonable, as the software is still in continuous update.
The problem is that the custom scripts don’t get run when you use the wifi send.
I think that it may be possible to monitor the log that Bambu Studio produces - which I think contains some of the temporary file names - then just jump in, unzip the file, run the script against the G-code and then zip it back up again.
Yes - certainly possible to try changing either Bambu Studio or Orca Slicer and then submitting a request to get it added to the base product.
Not a particularly high priority for me though to post process g-code - them main thing I would like to try doing is introducing long planned delays in overnight prints, and trying to improving things like purge to object, and maybe creating a sparce layers version of the prime tower (like P2PP does), and possibly a prime tower that comes out with a more useful shape.
A bigger priority for me is that I’d like to change one of the products too to give them to ability to pick up the colours on the initial import - have tried creating a 3mf file that has some of the correct XML in it to get Bambu Studio to accept extruder numbers - but is proving quite complicated. Currently I’m mostly setting colours by running a keyboard Maestro script automatically whenever you select ‘edit in parameter table’ in Bambu Studio.
I understood your workaround procedure but didn’t know why you needed to set up colours so many times.
I wanted to inject some wipe sequences after some gap infill extrusions so I stumbled upon this thread, then I realized the post-processing scripts functionality is not that useful since it only runs when the gcode is exported (in which case you can manually run the script yourself…)
then I figured out you can simply export the sliced plate, open the 3mf file using an archive manager (it’s a zip file), modify the gcode file either manually or through script, then zip everything again and rename the extension to 3mf, and then import into bambu sudio and send it to the printer
not exactly automatic but at least you can run the scripts and send to the printer
Interesting. I assumed BS would have insisted on re-slicing it.
Also I’ve had a bit of trouble getting BS to accept some unzipped/rezipped 3mfs - but it might just be the archiver I have been using (Mac built in) .
You are right. Writing a script to unzip the 3mf, open, edit the g-code file, and zip it again is more convenient. I succeeded with WinRAR, saving it using zip settings but using the .3mf extension. I have never tried in MacOS.
But I only did this to check how it works. I understand why some use it, but in the X1C, I never felt the need to make significant editions on the printer moves; for minor changes, I think the add custom g-code function is more convenient. In the S1Pro, it seems more practical to write macros within Klipper than editing the g-code.
JayZay - Thanks. - managed to work out how to get a 3mf file with GCODE in it via the ‘export all sliced file’ option in BS - it seems to create a GCODE and GCODE.3mf file that can be read back in - and presumably sent without further slicing.
This is pretty useful to me in its own right - the only thing that concerns me slightly is that there is an md5 file matching the GCODE - presumably to be able to determine whether the GCODE has been tampered with.
Did you manage to edit the GCODE and get it accepted ok by BS and the printer with doing anything with the md5 file?
Hi.
Yes, it worked. I tested until the print process started and then cancelled, as I didn’t want to print. If the file integrity was affected, the error should prompt at the start.
I also noticed the checksum file and understand and had the same question.
I tested it, and it seems (at least for me) that editing the g-code file content works.
However, the file’s integrity is checked, and contradictory info results in an error message in the slicer.
To be specific, I need time to carry out adequate tests.
Let me know if it works for you, too.