Hello Guest it is March 28, 2024, 12:37:29 PM

Author Topic: passing variable values from macro to macro , using parameters?  (Read 6389 times)

0 Members and 1 Guest are viewing this topic.

I want to be able to preserve the value of 'FileNum', (variable used in a macro), and access it from other macros after the macro that generated it is switched off, or use it in the same macro called again later in my Gcode. I tried this:-

Dim FileNum As Double

'Code arriving at a value for FileNum...

Param1() = FileNum

It tells me I have a type mismatch at the last line, which I don't understand, as the manual says that parameters are doubles, like my variable.

My variable is never more than 2 digits long, so doesn't have to be a double; I just thought it needed to be, in order to transfer its value to parameter1.

Am I not assigning the value of FileNum correctly to Param1()?
How can I pass values from one macro to another?

Thanks,

M21

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: passing variable values from macro to macro , using parameters?
« Reply #1 on: April 26, 2015, 04:16:56 PM »
One way is to write the value to a user DRO, and read it from there.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: passing variable values from macro to macro , using parameters?
« Reply #2 on: April 26, 2015, 04:43:41 PM »
That works a treat, Thanks.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: passing variable values from macro to macro , using parameters?
« Reply #3 on: April 26, 2015, 05:24:46 PM »
Param1() is a read only value.

Another way it to use the Gcode Vars 500-600

GetVar(500)
Setvar(500,22)

(;-) TP
Re: passing variable values from macro to macro , using parameters?
« Reply #4 on: April 27, 2015, 03:41:47 AM »
Ok, ta. Manual wasnt too clear on params being read only.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: passing variable values from macro to macro , using parameters?
« Reply #5 on: April 27, 2015, 04:26:15 AM »
Param1() is a FUNCTION and therefore is an rvalue (i.e. simply put, it can only appear on the right hand side of an expression).

e.g. x = Param1();
Re: passing variable values from macro to macro , using parameters?
« Reply #6 on: April 27, 2015, 02:36:09 PM »
I've tried both UserDro and Var ideas...

Var loses its value after Mach is shut down and restated, UserDro keeps its value.

Is this how it's supposed to work? Really didn't expect UserDro to keep its value...
Re: passing variable values from macro to macro , using parameters?
« Reply #7 on: April 27, 2015, 03:01:44 PM »
Although that appeared to be the case, I now find the following:-

It seems the value of Var is retained after Mach is shut down, but not when the PC itself is shut down, whereas UserDRO keeps its value in both cases.

I was hoping to set a variable to initialise at 0 any time Mach is started, and set to 1 after the first file has been loaded ( So another macro can tell if this is the first file loaded since Mach started up or not), but if both the above types retain their value after shutting down and restarting Mach, it won't work.

Is there a reliable way to clear the value of a Var or a UserDRO when Mach shuts down? Also, it would be useful to set up another 'flag' to show if reset has been pressed at any time since Mach was opened.

The macro (called from a Gcode test file) is this:-

Dim FirstFile As Double

FirstFile = GetVar(500)
Message FirstFile
If FirstFile <> 1 Then
   SetVar(500,1)
End If
« Last Edit: April 27, 2015, 03:06:28 PM by moorea21 »

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: passing variable values from macro to macro , using parameters?
« Reply #8 on: April 27, 2015, 03:28:52 PM »
You can make a macro to set the USerDRO to 0, and call it from the Initialization string when you first start Mach3.
Then add another macro to all your g-code files, to set the USerDRO to 1 if it's 0.
Gerry

2010 Screenset
http://www.thecncwoodworker.com/2010.html

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: passing variable values from macro to macro , using parameters?
« Reply #9 on: April 27, 2015, 03:43:10 PM »
That sounds good. It looks like I can also set another UserDRO to 1, and it can then be reset to 0 with a similar macro if Mach is reset, if I check 'Use init. on all resets', so hopefully both of these tasks should be do-able.

Is checking 'Use init on all resets' likely to have any unforeseen effects, if the initialisation string only contains the default string values, and a couple of calls to macros that reset the value of userDRO's or Vals? I don't want to find that this means something else won't work. Probably being over cautious now?

Thanks.