cp2004 / OctoPrint-GCodeMacros

Configure custom gcode macros you can use anywhere!
https://plugins.octoprint.org/plugins/gcode_macro
GNU Affero General Public License v3.0
7 stars 2 forks source link

Jinja2 not accessing other plugins #7

Closed jessemillar closed 2 years ago

jessemillar commented 2 years ago

I'm attempting to port some GCODE into a macro. My GCODE commands use Jinja2 to access values from other plugins. Works fine when I have the same GCODE in the Octoprint "GCODE Scripts" section but when I try to run my macro after defining it in GcodeMacros, it just doesn't run. I don't see any GCodeMacros log files and there's no terminal output when I try to run my macro.

M104 S{{ plugins.preheat.tool0|int() }} ;Heat nozzle
M109 S{{ plugins.preheat.tool0|int() }} ;Wait for nozzle
M702 ;Unload filament
cp2004 commented 2 years ago

The log file is the main octoprint.log. You'll probably see an error rendering the script output.

I haven't designed it to take in the same context as the rest of the gcode scripts, although I can see how that might be useful to have for things like smart preheat. I will look at the feasibility (there may be a simple thing I can import and use) of putting the same context into these scripts.

cp2004 commented 2 years ago

I've done some research into the possibility of adding this context to these gcode macros here, and have decided that it is not feasible to try and get other plugin's context into the gcode macros.

The OctoPrint hooks to get the extra variables are for the built in gcode scripts, I can't really support everything that would be expected there, and so it would be a messy hack. In the case of 'Smart Preheat', it specifically only reads the temperatures in beforePrintStarted, though maybe they are available everywhere after that is run.

jessemillar commented 2 years ago

Totally understandable. Thanks for looking into it!