Hello Guest it is April 18, 2024, 12:41:53 AM

Author Topic: Macro Tutorial  (Read 13208 times)

0 Members and 1 Guest are viewing this topic.

Macro Tutorial
« on: October 31, 2017, 03:02:12 PM »
I've been using Mach3 for few years, and up to now managed to avoid writing macros.  Now I need to produce some, and having read many of the posts, I am still stuck as to how to start.  Is there a tutorial anywhere that I have missed?  Just looking at the reference guide does not show the fundamental step by step first moves that I need, mainly because I am still at a very basic level.

Any help would be appreciated!

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Macro Tutorial
« Reply #1 on: October 31, 2017, 03:21:02 PM »
Look at some of the macros that are included with Mach3.
Or ask specific questions, and other members can maybe explain.

Or look at tutorials for VB programming, but they'll have far more info than you need.
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html

Offline Tweakie.CNC

*
  • *
  •  9,197 9,197
  • Super Kitty
    • View Profile
Re: Macro Tutorial
« Reply #2 on: November 01, 2017, 02:25:32 AM »
Check out the Video Tutorials - The Introduction to Scripting should get you started. http://www.machsupport.com/videos/

Tweakie.
PEACE
Re: Macro Tutorial
« Reply #3 on: November 01, 2017, 03:00:58 AM »
Hi David,
I was in very much the same position, had used Mach3 without having to get down and dirty writing macros. When I did it was a challenge and then I thought,
'what the hell...if I'm going to learn a new computer language it should be better than Visual Basic, or rather Cypress Enable, Mach3s VB subset, ie it should
be Lua and Mach4'.

Don't get me wrong Lua is a challenge too, maybe even more than VB. Lua itself is easy its once you start adding all Machs API calls and wxWidget calls and
Machs modular structure does it become complex. In addition the programming in Mach4 is modern style, that is to say it is Object Oriented in style and is
quite new and strange to someone like me who cut his teeth on procedural languages like Fortran.

It has taken a while but I am slowly gaining familiarity with Lua/Mach4 and its very satisfying. The complete combination of Lua/Mach/wx.Widgets is very VERY
capable and easily hoses Mach3  and VB into the weeds. I'm glad I made the switch, I was up for the challenge and have been rewarded with a much more modern
and capable toolset.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Macro Tutorial
« Reply #4 on: November 02, 2017, 12:36:56 PM »
Thank you for the replies.  My immediate interest is in implementing conditional jumps, such as if...then.  I needed a conditional statement in some code that I was writing, and the advice from the forum was that it cannot be done in Mach3, but could be done using a macro.Taking up ger21's point, could one of our members give me an example of an if command executed in a G code program by using a macro?

Many thanks.

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Macro Tutorial
« Reply #5 on: November 02, 2017, 01:11:00 PM »
You'd need to explain EXACTLY what you want to do. This may not be a trivial macro.
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Macro Tutorial
« Reply #6 on: November 03, 2017, 09:05:19 AM »
Hi Ger21

Thanks again for the quick reply.  A practical example is where a complex profile is being cut.  The program runs through various  cutting profiles at various depths etc. and at an appropriate point it tests the value of parameter #100.  #100 is a function of the thickness of the workpiece and the depth of cut.  Progressive cuts reduce #100, until when the tool breaks through the value of #100 reaches zero.  At this point the tool motion stops, or carries on in the program and does something else.  My intention is to use a Z axis height probe to derive the depths (surface and base) which will be built into the opening part of the program.  I wish to avoid simply using loops which will usually result in substantial over-travel into the material supporting the workpiece.

Example:

N1   {Piece of G code which carries out a number of actions, progressively reducing N
   #100 from, say, 5 down to 0 at which point the program jumps in accordance with the    IF statement}
N10   

.
.
.
.
IF [#100 EQ 0] GOTO 110   

GOTO 200

N110  {Another part of the program. Arrives here if #100=0}

N200 {A different part of the program.  Arrives here is #100 is not equal to 0}


I know that IF...THEN...ELSE and GOTO are available in Fanuc, but clearly not in Mach3.  However, there have been a number of posts that state that these functions can be implemented in Mach3 using a macro.  I have seen some examples of macros, but these use expressions that I have yet to learn.  The macros that come with Mach3 are similar - impenetrable without a primer.  There have been suggestions that I learn by looking at a few examples - although this rather like being advised to learn French by reading a few works by Proust in the original language.   :)

If you can give me an example for the above program I would be grateful.

Regards

Offline ger21

*
  • *
  •  6,295 6,295
    • View Profile
    • The CNC Woodworker
Re: Macro Tutorial
« Reply #7 on: November 03, 2017, 12:00:36 PM »
Quote
However, there have been a number of posts that state that these functions can be implemented in Mach3 using a macro.

Yes, but I've never seen one, and don't know how to do it.
I don't think you can actually jump to another point in the g-code, but I could be wrong. You can test for #100, but what you do after that would probably need to be done in the macro???

It would probably be something like this:

thickness = GetVar(100)
If thickness = 0 then
.....
Gerry

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

JointCAM Dovetail and Box Joint software
http://www.g-forcecnc.com/jointcam.html
Re: Macro Tutorial
« Reply #8 on: July 02, 2019, 09:41:15 AM »
I think Macro is good

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Macro Tutorial
« Reply #9 on: July 02, 2019, 02:24:30 PM »
From inside of teh macro you use a M98 Pxx to jump to a Oword in the loaded Gcode. It is a one way jump with NO return.

(;-) TP