Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add custom variables #4048

Closed
P-i-r-o opened this issue Apr 11, 2020 · 1 comment
Closed

[Feature Request] Add custom variables #4048

P-i-r-o opened this issue Apr 11, 2020 · 1 comment

Comments

@P-i-r-o
Copy link

P-i-r-o commented Apr 11, 2020

Hi

I wrote the script to temperature calibration tower that adds M104 command in the right places. To made it parametric I needed some variables, where i can store valiues. Unfortunately there's no free variables so I had to use some of already present and that not change gcode.
In my case i used filament cost, density and soluble to make it works.

Here it is:

{if false} ;temp tower mode: set filament to soluble to enable, filament cost is height change for temp change, filament density is temp decrement {endif}
{if (filament_soluble[0] == true) && (layer_z >= filament_cost[0] * ((layer_z + z_offset - layer_z % filament_cost[0]) / filament_cost[0])) && (layer_z < (filament_cost[0] * ((layer_z + z_offset - layer_z % filament_cost[0]) / filament_cost[0]) + layer_height)) }M104 S{temperature[0] - (filament_density[0] * ((layer_z - layer_z % filament_cost[0]) / filament_cost[0])) } {endif}

It would be very helpful to be able to define and use variables inside custom gcode section. This code could be more clear and editable then and also will allow others to create other macros.
Enough for now could be some new hardcoded variables. Such like I have already used, but not used nowhere else.
Is this a new feature request?
Yes

lukasmatena pushed a commit that referenced this issue Mar 31, 2023
Implements #4048 #7196

Syntax:

(global|local) variable_name =
	(scalar_expression|vector_variable|array_expr|initializer_list)

array_expr := array(repeat, value)
initializer_list := (value, value, value, ...)

The type of the newly created variable is defined by the type
of the right hand side intitializer.

Newly declared variable must not override an existing variable.
Variable may be assigned with global|local expression, but its type
must not be changed.

Newly the assignment operator also accepts the same right hand expressions
as the global|local variable definition.
@lukasmatena
Copy link
Collaborator

Support for local and global variables was implemented in 2.6.0-alpha6. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants