Hello Guest it is July 18, 2025, 01:38:19 AM

Author Topic: Hello folks. Need macro help please  (Read 628 times)

0 Members and 1 Guest are viewing this topic.

Hello folks. Need macro help please
« on: July 09, 2025, 10:50:11 AM »
How do I create a macro or a script to be activated via a keyboard input to move my AvidCNC to the position of x=1.3, y=1.3 and Z=4?  I would like to do this to center my spindle over the touchplate to save time while changing between tools on multiple toolpaths on the same project.  I am printing the technical information on Mach 4 but I just thought that someone might know this.
Re: Hello folks. Need macro help please
« Reply #1 on: July 15, 2025, 04:26:47 PM »
You can do this with an on screen button if you'd like.  You can use the Go To Work Zero button as an example and then the Go To Work Zero Function in the screen load script and copy and modify it how you would like.
But you can do this with a keyboard input if you want.
Set a keyboard button in the Keyboard Plugin.  Name the input and select a Key, do not assign it a function, just click the function and close it so it says "none". 
Close mach4 to initialize the change.
In the inputs tab in the Mach4 Configure, activate an input and set the input's device to Keyboard and then in the dropdown select the keyboard input you want to use.

In the screen load script (in the screen editor), use the GoToWorkZero function as an example.  Copy the function and rename it whatever you like and paste it right below the gotoworkzero function.
Name it GoToToolSetter() if you want.  Adjust the code to do what you want.  If you have working home switches and you know what your position is going to always be, you can use G53 G00 X## Y## Z##.  this will use the machine coordinates.  Otherwise, just use G90 G00 X## Y## Z##.
I would suggest looking at the gotoworkzero code again, it uses a safe move to Z0 then moves XYA and the moves Z again. 

At the top of the screen load script in the SigLib, there are examples of how to use and input to run a function.  Copy one of those and set it to your input number you set up in the Mach4 configure and then set it to run your code. 

---------------------------------------------------------------
-- Go To Tool Setter function.
---------------------------------------------------------------
function GoToToolSetter()
    mc.mcCntlMdiExecute(inst, "G00 G53 Z0\nG53 G00 X2.00 Y0.50\nG53 G00 Z-1.0")--With Z moves & Machine Coords.
   --mc.mcCntlMdiExecute(inst, "G90 G00 X2.00 Y0.50")--Without Z moves & Without Machine Coords.
end

[mc.ISIG_INPUT1] = function (state) -- this is an example for a condition in the signal table.
         if (state == 1) then
          GoToToolSetter()
       end
end,

« Last Edit: July 15, 2025, 04:28:47 PM by Cbyrdtopper »
Chad Byrd
Re: Hello folks. Need macro help please
« Reply #2 on: July 15, 2025, 04:29:08 PM »
Thank you very much!  A screen button would be much better.

Mike
Re: Hello folks. Need macro help please
« Reply #3 on: July 15, 2025, 04:31:18 PM »
Same process for the code.
Set the function up in the screen load script exactly the same as stated above.  Only this time you don't need to set the input up in the SigLib.  Just the function like the gotoworkzero. 
Then just add a button to the screen and in the "Clicked Script" just put the function in the code.  GoToToolSetter()
Chad Byrd