• Tags
  • Documentation
  • Order
  • Register
  • Login
Duet3D Logo Duet3D
  • Tags
  • Documentation
  • Order
  • Register
  • Login

Triggering a macro by G-command

Scheduled Pinned Locked Moved
Tuning and tweaking
4
12
884
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    RajaaKahel
    last edited by RajaaKahel 6 Apr 2019, 18:39 4 Jun 2019, 18:28

    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.

    1 Reply Last reply Reply Quote 0
    • ?
      A Former User
      last edited by 5 Jun 2019, 12:16

      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)

      undefined undefined 2 Replies Last reply 5 Jun 2019, 12:58 Reply Quote 0
      • undefined
        RajaaKahel @A Former User
        last edited by 5 Jun 2019, 12:58

        @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..

        ? 1 Reply Last reply 5 Jun 2019, 13:19 Reply Quote 0
        • undefined
          T3P3Tony administrators
          last edited by 5 Jun 2019, 13:00

          @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.

          www.duet3d.com

          undefined 1 Reply Last reply 5 Jun 2019, 21:19 Reply Quote 0
          • ?
            A Former User @RajaaKahel
            last edited by 5 Jun 2019, 13:19

            @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.

            undefined 1 Reply Last reply 5 Jun 2019, 21:29 Reply Quote 0
            • undefined
              wilriker @A Former User
              last edited by 5 Jun 2019, 13:49

              @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.

              Manuel
              Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
              with probably always latest firmware/DWC (incl. betas or self-compiled)
              My Tool Collection

              1 Reply Last reply Reply Quote 0
              • undefined
                RajaaKahel @T3P3Tony
                last edited by 5 Jun 2019, 21:19

                @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.

                1 Reply Last reply Reply Quote 0
                • undefined
                  RajaaKahel @A Former User
                  last edited by RajaaKahel 6 May 2019, 21:29 5 Jun 2019, 21:29

                  @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.

                  ? 1 Reply Last reply 5 Jun 2019, 22:34 Reply Quote 0
                  • ?
                    A Former User
                    last edited by A Former User 6 May 2019, 22:06 5 Jun 2019, 22:00

                    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)

                    undefined 1 Reply Last reply 5 Jun 2019, 22:12 Reply Quote 0
                    • undefined
                      RajaaKahel @A Former User
                      last edited by 5 Jun 2019, 22:12

                      @bearer
                      Thank you. I'll see what I come up with.

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User @RajaaKahel
                        last edited by A Former User 6 May 2019, 22:38 5 Jun 2019, 22:34

                        @rajaakahel
                        https://pastebin.com/JNF60tc5

                        There 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..)

                        undefined 1 Reply Last reply 6 Jun 2019, 19:05 Reply Quote 1
                        • undefined
                          RajaaKahel @A Former User
                          last edited by 6 Jun 2019, 19:05

                          @bearer
                          Thank you! Will check it out.

                          1 Reply Last reply Reply Quote 0
                          10 out of 12
                          • First post
                            10/12
                            Last post
                          Unless otherwise noted, all forum content is licensed under CC-BY-SA