Variables in macros

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Variables in macros

Postby Battwell » Thu Nov 03, 2016 5:28 pm

What is correct syntax to set something to a var in a macro ?
I want to use an if statement to check a variable to see if a tool should be probed or not
Tried for an hour - given up !
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Variables in macros

Postby ger21 » Thu Nov 03, 2016 5:47 pm

getcar() and setvar(). But you need to be using version 1.2028
http://www.cncdrive.com/UCCNC/setup_1.2028.exe
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Variables in macros

Postby Battwell » Thu Nov 03, 2016 5:51 pm

Ah. I'm on 2026. Maybe Why
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Variables in macros

Postby cncdrive » Thu Nov 03, 2016 10:43 pm

In earlier versions you could read and write the ivars array, e.g.
ivars[10] = 1.234;
double myvar = ivars[10];

The new Getvar and Setvar functions doing the same, setting the members of the ivars array which are the variables you can code with the # suffix in g-code.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Variables in macros

Postby Battwell » Fri Nov 04, 2016 11:29 am

thanks- i couldnt find that command documented anywhere.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Variables in macros

Postby ger21 » Fri Nov 04, 2016 2:44 pm

Is there a list of vars somewhere, and is there a range that's safe for users to use?
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Variables in macros

Postby Battwell » Fri Nov 04, 2016 3:51 pm

ok. couldnt get syntax right for old ivars version so i installed 2028.

full syntax that works is
double myvar=exec. Getvar(1); // for variable #1

then used
if(myvar>0)
{

skip this code

}

which works.
except the macro just seems to stop and end after the }
is there a goto function i can use instead ? if so how to write that please
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Variables in macros

Postby ger21 » Fri Nov 04, 2016 4:05 pm

I don't understand what you want it to do?
Can you use "else"?
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Variables in macros

Postby Battwell » Fri Nov 04, 2016 4:27 pm

it was just to skip my probing section in my m6 macro.
it just doesnt resume after the }
(doesnt run the code after ) i havnt worked out why yet.
maybe adding else will work !
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Variables in macros

Postby ger21 » Fri Nov 04, 2016 4:36 pm

If you want the code to run if myvar > 0, then your code should all be inside of the }.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 2 guests