Triggering a macro by G-command
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?
M98 P"macro.g" will run macro.g
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.
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.
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?
@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.
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)
Thank you. I'll see what I come up with.
Thank you! Will check it out.