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] Parameterised Macros #12

Open
cp2004 opened this issue Jul 14, 2022 · 3 comments
Open

[Feature Request] Parameterised Macros #12

cp2004 opened this issue Jul 14, 2022 · 3 comments
Labels
request New feature or request

Comments

@cp2004
Copy link
Owner

cp2004 commented Jul 14, 2022

I am wondering if parameterized macros may be cool.

It would be like this:

@command <params>

And available in the macro like

{{ param }}

I need to think of some example use-cases for this first, before developing it - let me know if you read this & think of something!

@cp2004 cp2004 changed the title [Feature Request [Feature Request] Parameterised Macros Jul 14, 2022
@cp2004 cp2004 added the request New feature or request label Jul 14, 2022
@napter
Copy link

napter commented Jul 18, 2022

I just came here to ask if this was possible / post a feature request! My primary use case is to be able to selectively run parts of the script by sending a parameter.

Another use case, if the variable can retain its value across macros, would be to set a printer name and then later use that to determine things like print temperature.

@CmdrCody51
Copy link

CmdrCody51 commented Aug 10, 2022

I have 'parameters' working to an extent.
I use this to decide if I want to do a First_Layer check on my prints.

  1. Have GCODE Systems Commands plugin. This uses an 'OCTO#' to call shell scripts from GCode files or the 'terminal'.
  2. Have Custom Control Editor plugin. This puts buttons on the Control tab. (MUST USE https://github.com/jneilliii version)
  3. Have Gcode Macros plugin.

1.) I use OCTO300 to turn my flag 'false' and OCTO301 to turn my flag 'true'. (I have a lot of them)
The 'flag' resides in '/home/pi/.octoprint/data/gcode_macro/my_Logic.flag'.
The script for OCTO300 is: sed -i 's/true/false/' /home/pi/.octoprint/data/gcode_macro/my_Logic.flag
The script for OCTO301 is: sed -i 's/false/true/' /home/pi/.octoprint/data/gcode_macro/my_Logic.flag
The file itself is: {% set mine.my_State = true %} {Notice the mine.! More later.)
2.) I define two buttons in Custom Controls: Logic True and Logic False. They just contain the OCTO codes above.
3.) In Gcode Macros I define @First_Layer as:
{% set mine = namespace(my_State=false) %} {% set message = 'First Layer Check' %} {% include 'Do_Pause.macro' %}
Now... the namespace allows variables to be passed through jinga2 scripts to if/for loops.
4.) I manually enter the following script to /home/pi/.octoprint/data/gcode_macro/ called "Do_Pause.macro"

 {% include 'my_Logic.flag' %}
 {% if mine.my_State %}
 M400 ; complete all motion
 G60 ; store XYZF (fw)
 G91 ; incremental
 G1 Z1 ; lift Z to clear part
 G90 ; back to absolute
 G1 X2 Y217 ; clear the build area
 M400 ; complete all motion
 OCTO203 ; turn lights on
 {% if message is defined %}
 M117 {{ message }}
 {% endif %}
 M300 P1000 ; beep if you got em
 M1 ; pause using printers pause
 OCTO202 ; turn lights off
 G61 ; return to saved position (fw)
 {% endif %}

G60 and G61 stores and restores X,Y,Z and F in current Marlin firmware.
I can see placing many variables into a 'Settings.macro' and running such things as temperature, feedrate and flowrate modifiers.

@jneilliii
Copy link
Contributor

jneilliii commented Mar 31, 2024

Have a perfect use case for this (https://community.octoprint.org/t/how-to-get-the-extruder-that-is-enabled-in-gcode-script-after-print-job-is-paused/57694/4?u=jneilliii) and potential idea for making the parameters available in other macros. If you were to use environment variables similar to GCode System Commands plugin, you could then do template.render(env=os.environ) couldn't you to extract the data out as {{ env.my_env_variable }}?

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

No branches or pull requests

4 participants