Jump to content
Ultimaker Community of 3D Printing Experts
bcsteeve

Possible to make dynamic gcode in cura?

Recommended Posts

Cura knows the size of the object being sliced (it says it down in the bottom).  Let's say I want to send a G29 command to the printer suffixed by the size of the print job.  For example, I'm printing a 50x50 object I see no reason to wait 5 minutes while it autolevels across a 300 x 300 bed.

 

I see other applications as well and I wondered if there was a way for me to instead of say "send G29 at print start", say "send G29 X{x of project] Y{y of project]"  or even better (if I want to get complex) something like this psuedo code:  "send G29 P{int(print size / 25)"  {the idea being to scan a smaller grid number for a smaller grid size).

 

I hope I'm making sense.


Basically:  can variables be used to dynamically generate gcode based on data generated by Cura (primarily object size)?

Share this post


Link to post
Share on other sites

It's not currently possible, or at least not easily.

 

We expose all settings through the bracket syntax in the start and end g-code, but nothing other than those settings except the current date and time. Those are the only thing you can use when typing start/end g-code in the interface with the Machine Settings menu. See here for the source code that handles the bracket syntax: https://github.com/Ultimaker/Cura/blob/6a053a9f46c56a94cfaf611cb55376b4d0ad09d1/plugins/CuraEngineBackend/StartSliceJob.py#L270-L285

 

When you're writing a definition file (.def.json) a few more things will be possible if you specify the "value" property instead of "default_value". The "value" property can be any arbitrary Python expression, so you could make calculations like "G29 P" + str(int(machine_width / 25)) or something, and all the setting names have already been filled in as variables. There are other (hidden) functions available then as well, for instance extruderValues(setting_name) which gets a list of all values for a setting for each extruder. But there is nothing there either that can get the size of the print.

 

Warning: I'm getting gradually more technical here...

 

There is a vulnerability of sorts that allows you to devise a setting value that escapes the sandboxed environment in which the setting expressions are evaluated, and you can obtain data from the internals of Cura this way, including the dimensions and positions of the models. I won't disclose it here. But doing this will have problems with updating the setting value if the build volume changes, so it's not going to work reliably.

 

Also for the purpose of bed levelling you'd probably want to know the size of the final print rather than the size of the input models. The actual print can be quite different due to brims, rafts and horizontal expansion (of model and/or support). Most of these can be predicted beforehand (you know the desired brim width and such). Some of them can't though, for instance if you have conical support enabled. In those cases it is really impossible to get the dimensions of the print before slicing has completed.

 

I'll shoot in a feature request ticket to add the size of the input models as a key replacement for the bracket syntax. No promises, of course. Our backlog is long.

https://github.com/Ultimaker/Cura/blob/6a053a9f46c56a94cfaf611cb55376b4d0ad09d1/plugins/CuraEngineBackend/StartSliceJob.py#L275
Edited by ghostkeeper
Saying that I'll make a feature request.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

Terms of Use Privacy Policy