Triggering a macro by G-command
-
Hi,
How can I make a macro triggered by a specific G-command? (for example by Z-lift command).
If it's possible, can I make it for a specific tool only?
Thanks. -
M98 P"macro.g" will run macro.g
https://duet3d.dozuki.com/Wiki/Gcode#Section_M98_Call_Macro_Subprogram
In adittion any unkown G-code will try to execute a macro with the same name, not sure if it allows overriding existing code but you could always try to make a macro called T1.g and see if it is triggered if you select tool 1 by running the T1 G-code. (No idea if that'll work or if it'll break something as the same macro would probably have to do whatever the built in command also does, but apart from that there is no support for conditional G-code)
-
@bearer Thanks for the reply.
What I want is to call a macro file automatically only when a Z-lift is happening.
I'm not sure if that's possible. Maybe I have to look for a gcode editor to automatically find all Z-lifts of a certain tool and adding a macro call command, again not sure if that's possible.. -
@RajaaKahel By Z Lift, do you mean Z-Hop that is put in by the slic3r for travel moves? Depending on your slicer you may be able to modify it to add the macro call to every Z-Hop.
-
@rajaakahel said in Triggering a macro by G-command:
What I want is to call a macro file automatically only when a Z-lift is happening
That sounds like you're better off getting the slicer to do for you as Tony suggests or writing a script that parses the g-code before sending it to the Duet.
Maybe if you explain what the end goal is you may get some alternative suggestions on how to achieve it.
-
@bearer said in Triggering a macro by G-command:
In adittion any unkown G-code will try to execute a macro with the same name, not sure if it allows overriding existing code [...]
It won't. It only looks for macros with that name after it checked against the list of known ones and did not find a match.
-
@t3p3tony
Yes I mean Z-Hop. I use Simplify3D, do you know how I can do that? Do you know any slicer that can do that?
Thank you. -
@bearer Can you recommend me where to start reading to learn how to do that with with the gcode?
The goal is to run a servo that will cut a fiber line that is being printed from a special nozzle during Z-hop.
Thank you. -
Python or Perl are generic scripting languages.
You'd open the sliced file, and a new empty file, and read the sliced file line by line. For every line read look for Z and parse the numerical value, compare it to the last Z value.
If no Z value output the line to the new file.
If the Z value has decreased store the Z value and output the line to the new file
If the Z value has increased store the Z value and output the command(s) necessary to make the cut.
Close all files.I think that should do the trick. (unless you need the fiber not to be cut at layer changes, then you'd also need to look for hints from the slicer of layer changes, or maybe have different z-hop height to layer heights to be able to distinguish)
-
@bearer
Thank you. I'll see what I come up with. -
@rajaakahel
https://pastebin.com/JNF60tc5There are some links to help explain what it does, maybe it'll give you a rough idea of one possible solution.
(Disclaimer: I don't really write Perl code, so take it with a grain of salt..)
-
@bearer
Thank you! Will check it out.