Machsupport Forum

G-Code, CAD, and CAM => G-Code, CAD, and CAM discussions => Topic started by: wingnut on March 12, 2016, 11:12:06 AM

Title: Set Variable to Current Axis Position in G-Code
Post by: wingnut on March 12, 2016, 11:12:06 AM
I would like be able to assign the current Y position to a variable in G-Code. This variable would be updated at various points throughout the program. Something similar to the %(2) function in ShopBot. Is this available via a G or M Code, or is this something that would require VB and some type of GETDRO function?

Depending on the options available, what is considered "Best Practice" for accomplishing this in Mach3?

-Thank you.
Title: Re: Set Variable to Current Axis Position in G-Code
Post by: ger21 on March 12, 2016, 02:52:32 PM
Create an M code with VB Script, and call the M code in your g-code.
Title: Re: Set Variable to Current Axis Position in G-Code
Post by: wingnut on March 13, 2016, 03:33:49 PM
Thank you. I have created a macro M801 with the following.

Dim Yaxis As Integer
Yaxis = 801
SetVar (60,Yaxis)

In my G-Code I have a variable (#60) that represents the YLoc. At the time of the call to M801, will the #60 var will be updated with the current Y axis location? As I call M801 later in the program the #60 var will reflect the new location?

I appreciate the help with this.
Title: Re: Set Variable to Current Axis Position in G-Code
Post by: ger21 on March 13, 2016, 05:06:58 PM
Is your Y axis value actually going to be an integer, or are you trying to round it off to one? SetVar is expecting a double, so you might get a type mismatch if you try it that way.

Try:

Dim YAxis
Yaxis = GetOEMDRO(801)
SetVar(60,Yaxis)


The answer to both of your questions is yes, it should.