What's new
What's new

First time making a Macro Program

EyeEmTrash

Aluminum
Joined
Feb 24, 2023
I am making a Macro Program for the first time. I think I am starting to understand it a little bit better. At my job we make a certain part that is pretty much the same, just in different OD's and some minor changes in other dimensions. I was thinking that Macro Programming would be perfect for this as I can just change variables instead of writing 12 different programs. I just started to write it and I will have other variables added when I think of them. I am hoping someone could give me advice and tell me if my program is good so far and whether or not I am on the right track in doing this the best way. Any tips would be appreciated.

Edit: I should also add that the parts I make are pretty simple. I am probably making the program more complicated then it has to be. I just figured that the more variables I add at the top, the less I have to go digging through the program to make changes. The parts come pretty much cut to length, I just have to trim around 3/16 off every piece but they do vary depending on who cuts them. I can have 2 different parts with the same OD, with a different length and different drill length as well.



#100=1.5(SIZE OF MATERIAL)
#101=1.5(OD TOP)
#102=1.495(OD BOTTOM)
#103=1.5(DEPTH OF BOTTOM SOCKET)
#104=[#100+.2](OD X SAFE HEIGHT)

#106=.04(OD ROUGH DOC)
#107=.005(OD FINISH DOC)
#108=.01(ROUGH OD FEED)
#109=.005(FINISH OD FEED)
#110=.125(HOW MUCH TO FACE)
#111=.02(RADIUS/CHAMFER TOP)
#112=.02(RADIUS/CHAMFER BOTTOM)

#113=.900(OD THREAD LENGTH)
#114=.0438(OD THREAD HEIGHT)
#115=.0767(OD THREAD FEED RATE)

#116=5.5(TOP DRILL DEPTH)
#117=.3(TOP DRILL POINT OFFSET)
#118=.2(TOP DRILL DOC)
#119=

G80G00M09
G28U0W0
M05
M01

N1(STOP)
G80G00M09
G28U0W0
M05
M01

T1010
G50S800

G99G97G42G00X[#100-.2]Z#110
M00
(PULL MATERIAL TO STOP)
Z[#110+1.0]

N2(ROUGH FACE AND CHAMFER)
G80G00M09
G28U0W0
M05
M01

T1010
G50S800
G99G96G42
G00X3.0Z1.0


#150=[#110-#106](Z FACING)

N3

IF[#150LE[#106+#107]]GOTO4
G00X#104
Z#150
G01X0.0F#108
G00Z[#150+.2]

#150=[#150-#106]
GOTO3

N4
G00X#104
Z#107
G01X0.0F#108
G00Z[#150+.2]
 
Last edited:
That looks like a lot of variables to potentially fuck up. I think I'd write different programs.
Make user defined variables for your 12 part numbers and then use those to determine which variables are used elsewhere in the program. That way operators only have to pick/change the part number variable each time they go run the program, everything else is done automatically.
 
There is a huge “sticky” thread at the top of this forum dedicated to macro programming. There are some really good posts in there, mostly from user angelw. You should spend some time reading those and you’ll have a much better understanding of how to structure your macro and the advantages of using local variables over common variables in many applications.
 
Make user defined variables for your 12 part numbers and then use those to determine which variables are used elsewhere in the program. That way operators only have to pick/change the part number variable each time they go run the program, everything else is done automatically.
IDK how to do that lol. I guess I gotta do some more research
 
Make user defined variables for your 12 part numbers and then use those to determine which variables are used elsewhere in the program. That way operators only have to pick/change the part number variable each time they go run the program, everything else is done automatically.
if you think thats bad then you should see my program now
 
That looks like a lot of variables to potentially fuck up. I think I'd write different programs.
This is a good point. Once variables are set for a part you shouldn't have to reset each time the part comes around.
Make user defined variables for your 12 part numbers and then use those to determine which variables are used elsewhere in the program. That way operators only have to pick/changee part number variable each time they go run the program, everything else is done automatically.
You can call a different subprogram for each part number and set the common variables in the sub. Or as simple as jumping

#1=20 (run medium widget)
(N10 small widget)
(N20 medium widget)
(N30 large widget)

GOTO[#1]

N10 (SET SMALL #)
GOTO100
N20(SET MEDIUM #)
GOTO100
N30(SET LARGE#)
GOTO100

N100 (MACHINE PART)
M30

Many ways to do this just pick the one you like best.

Learn about common and local variables.

BTW, good use of comments in your code. Of course your example would be tough to decipher without comments, but good job nonetheless. I'm surprised by how many guys will not document their programs or show their work.
 
This is a good point. Once variables are set for a part you shouldn't have to reset each time the part comes around.

You can call a different subprogram for each part number and set the common variables in the sub. Or as simple as jumping

#1=20 (run medium widget)
(N10 small widget)
(N20 medium widget)
(N30 large widget)

GOTO[#1]

N10 (SET SMALL #)
GOTO100
N20(SET MEDIUM #)
GOTO100
N30(SET LARGE#)
GOTO100

N100 (MACHINE PART)
M30

Many ways to do this just pick the one you like best.

Learn about common and local variables.

BTW, good use of comments in your code. Of course your example would be tough to decipher without comments, but good job nonetheless. I'm surprised by how many guys will not document their programs or show their work.
If I understand what you are saying, I think the problem with that is that I can have 2 parts that are the same OD, but different length and different drill depth. It depends on what the customer wants. I figured that the more variables I add at the top, all I would have to do in theory is just change a few numbers at the top of the program instead of digging through. I know I am definitely not writing it in the most simplistic manner but I will upload once I am done for anyone who wants to proofread my mess lol. Also I still dont know how to do what you wrote. I am still learning.
 
Also I still dont know how to do what you wrote. I am still learning.
Look closely you can figure it out. Doesn't make sense for 2 or 3 variables but does if you need to change a lot.
That looks like a lot of variables to potentially fuck up. I think I'd write different programs.
There is truth in this. Rather than check each variable every time you switch to a different part, do it once and save it.

Once and done wins the day.
 
Agree, read the article at the top.

Look at it like this, your part program is the list of variables for a specific part with the sub call. Store the subprogram in the control. That way you can also break up the features into their own subs. Say only 2 of 50 parts get an additional feature just call that sub in the main program.
We run parts like this all the time

This is your part program

O0100 (WIDGET 1)
#100=1.5(SIZE OF MATERIAL)
#101=1.5(OD TOP)
#102=1.495(OD BOTTOM)
#103=1.5(DEPTH OF BOTTOM SOCKET)
ETC...
(PARAMETERS LOADED)

N10 T126 M06
(6.0 IN. FACE MILL)
G90 G00 B90.
M98 P8001 (FACE MILL BASE) <--- CALLS SUB PROG
G00 G91 G28 Z0.0 M05 M09
M00
M30
%

Program O0101 widget 2
Program O0102 widget 3
and so on

This is your sub program in the control

O8001
N1(STOP)
G80G00M09
G28U0W0
M05
M01

T1010
G50S800

G99G97G42G00X[#100-.2]Z#110
M00
(PULL MATERIAL TO STOP)
Z[#110+1.0]
etc...
 
Agree, read the article at the top.

Look at it like this, your part program is the list of variables for a specific part with the sub call. Store the subprogram in the control. That way you can also break up the features into their own subs. Say only 2 of 50 parts get an additional feature just call that sub in the main program.
This is what I would recommend.

I have a subroutine that sets all of my extended offsets for our part families. At the beginning of the "main" programs, I set 4 variables. I have 30 of these "main" programs that use the same 4 variables. These 4 variables dictate which extended offsets are set for that specific part. In your application, you would essentially have 12 programs where the meat is the same, but your would have variables at the beginning that dictate what happens in the sub routine. You could also use a G65 line (if your controller supports them) and use that to set the variables for your subroutine.

OP, I am far from the best at this, but I do have pretty good documentation on how I accomplished it. If you think seeing something like this would help, PM me and I can send you a copy of my program as well as the supporting documentation.
 
I probably also should have explained that my job is a mess, the machines are crap, the tools are crap. I just finished my complicated macro yesterday. I will be proofreading it today and probably pull my hair out. Once that is done, I can post it if anyone wants to go bald with me trying to understand it. After that, I will look into all of your suggestions into making it simpler. Appreciate all of your help.
 
Ok I have a new question,
Agree, read the article at the top.

Look at it like this, your part program is the list of variables for a specific part with the sub call. Store the subprogram in the control. That way you can also break up the features into their own subs. Say only 2 of 50 parts get an additional feature just call that sub in the main program.
We run parts like this all the time

This is your part program

O0100 (WIDGET 1)
#100=1.5(SIZE OF MATERIAL)
#101=1.5(OD TOP)
#102=1.495(OD BOTTOM)
#103=1.5(DEPTH OF BOTTOM SOCKET)
ETC...
(PARAMETERS LOADED)

N10 T126 M06
(6.0 IN. FACE MILL)
G90 G00 B90.
M98 P8001 (FACE MILL BASE) <--- CALLS SUB PROG
G00 G91 G28 Z0.0 M05 M09
M00
M30
%

Program O0101 widget 2
Program O0102 widget 3
and so on

This is your sub program in the control

O8001
N1(STOP)
G80G00M09
G28U0W0
M05
M01

T1010
G50S800

G99G97G42G00X[#100-.2]Z#110
M00
(PULL MATERIAL TO STOP)
Z[#110+1.0]
etc...
ok I think I get what you are saying now. In other words take the program I wrote, turn that into a subprogram and then make a bunch of programs for every part and put the variables in there, instead of changing the variables every time. Am i getting that right? Im slow sometimes
 
Ok I have a new question,

ok I think I get what you are saying now. In other words take the program I wrote, turn that into a subprogram and then make a bunch of programs for every part and put the variables in there, instead of changing the variables every time. Am i getting that right? Im slow sometimes
You got it. That makes your sub programs more universal and less chance of fat fingering a variable because they are locked in your main program.
 
You got it. That makes your sub programs more universal and less chance of fat fingering a variable because they are locked in your main program.
ok one more question, does this work for the main program? in other words, just the variables, a home, sub program callout and then end program home?

o1234(TAPERED BOTTOM)

(#150-160 ARE USED)

#190=1010(OD ROUGH TOOL)
#191=0202(OD FINISH TOOL)
#192=0303(OD THREAD TOOL)
#193=0101(SPOT DRILL TOOL)
#194=0606(TOP DRILL TOOL)
#195=0505(BOTTOM DRILL TOOL)
#196=0808(TAPPING TOOL)

#100=1.5(OD OF MATERIAL)
#101=1.5(OD TOP)
#102=1.495(OD BOTTOM)
#103=-1.5(DEPTH OF BOTTOM SOCKET)(NEGATIVE)
#110=.125(HOW MUCH TO FACE TOP)
#113=.06(HOW MUCH TO FACE BOTTOM)
#116=-5.5(TOP DRILL DEPTH)(NEGATIVE)
#117=.625(DRILL OD, FOR TOOL SAFETY)
#142=.900(OD THREAD LENGTH)

#104=#100+#105(OD X SAFE HEIGHT)
#105=.2(SAFE RETRACT)
#106=.04(OD ROUGH DOC)
#107=.005(OD FINISH DOC)
#108=.01(ROUGH OD FEED)
#109=.005(FINISH OD FEED)
#111=.02(RADIUS/CHAMFER TOP)
#112=.02(RADIUS/CHAMFER BOTTOM)

#127=.2(BOTTOM TAPER Y)
#128=.05(BOTTOM TAPER X)

#140=-.8(TAPPING DEPTH)(NEGATIVE)
#141=.0769(TAPPING FEED RATE)
#143=.0438(OD THREAD HEIGHT)
#144=.0714(OD THREAD FEED RATE)
#145=.014(INITIAL OD THREAD CUT)

#118=.4(INITIAL TOP DRILL DOC)
#119=.2(DEEP TOP DRILL DOC)
#120=.01(TOP DRILL FEED)
#121=.005(INITIAL TOP DRILL FEED)
#122=.02(INITIAL RAPID DRILL FEED)
#123=.1(RAPID DRILL FEED)
#124=15.0(DRILL DWELL TIME OUTSIDE OF PART)
#125=20.0(DRILL DWELL TIME INSIDE OF PART)
#126=-3.0(POINT TO START DEEP DRILL CYCLE)(NEGATIVE)

#130=.5(SPOT DRILL TOP DOC)
#131=.3(SPOT DRILL BOTTOM DOC)
#132=.005(SPOT DRILL FEED)

#135=-1.2(BOTTOM DRILL DEPTH)(NEGATIVE)
#136=.2(BOTTOM DRILL DOC)
#137=.01(BOTTOM DRILL FEED)
#138=10.0(BOTTOM DRILL OUTSIDE DWELL)
#139=6.0(BOTTOM DRILL INSIDE DWELL)

IF[#105LE#110]GOTO2(SAFETY LINE)
IF[#105LE#113]GOTO2(SAFETY LINE)
IF[#140LE[#135+.1]GOTO2(SAFETY LINE)

N1(HOME)
G80G00M09
G28U0W0
M05
M01

M98P9001

N2(END PROGRAM)
G80G00M09
G28U0W0
M05
M30
 
ok one more question, does this work for the main program? in other words, just the variables, a home, sub program callout and then end program home?

o1234(TAPERED BOTTOM)

(#150-160 ARE USED)

#190=1010(OD ROUGH TOOL)
#191=0202(OD FINISH TOOL)
#192=0303(OD THREAD TOOL)
#193=0101(SPOT DRILL TOOL)
#194=0606(TOP DRILL TOOL)
#195=0505(BOTTOM DRILL TOOL)
#196=0808(TAPPING TOOL)

#100=1.5(OD OF MATERIAL)
#101=1.5(OD TOP)
#102=1.495(OD BOTTOM)
#103=-1.5(DEPTH OF BOTTOM SOCKET)(NEGATIVE)
#110=.125(HOW MUCH TO FACE TOP)
#113=.06(HOW MUCH TO FACE BOTTOM)
#116=-5.5(TOP DRILL DEPTH)(NEGATIVE)
#117=.625(DRILL OD, FOR TOOL SAFETY)
#142=.900(OD THREAD LENGTH)

#104=#100+#105(OD X SAFE HEIGHT)
#105=.2(SAFE RETRACT)
#106=.04(OD ROUGH DOC)
#107=.005(OD FINISH DOC)
#108=.01(ROUGH OD FEED)
#109=.005(FINISH OD FEED)
#111=.02(RADIUS/CHAMFER TOP)
#112=.02(RADIUS/CHAMFER BOTTOM)

#127=.2(BOTTOM TAPER Y)
#128=.05(BOTTOM TAPER X)

#140=-.8(TAPPING DEPTH)(NEGATIVE)
#141=.0769(TAPPING FEED RATE)
#143=.0438(OD THREAD HEIGHT)
#144=.0714(OD THREAD FEED RATE)
#145=.014(INITIAL OD THREAD CUT)

#118=.4(INITIAL TOP DRILL DOC)
#119=.2(DEEP TOP DRILL DOC)
#120=.01(TOP DRILL FEED)
#121=.005(INITIAL TOP DRILL FEED)
#122=.02(INITIAL RAPID DRILL FEED)
#123=.1(RAPID DRILL FEED)
#124=15.0(DRILL DWELL TIME OUTSIDE OF PART)
#125=20.0(DRILL DWELL TIME INSIDE OF PART)
#126=-3.0(POINT TO START DEEP DRILL CYCLE)(NEGATIVE)

#130=.5(SPOT DRILL TOP DOC)
#131=.3(SPOT DRILL BOTTOM DOC)
#132=.005(SPOT DRILL FEED)

#135=-1.2(BOTTOM DRILL DEPTH)(NEGATIVE)
#136=.2(BOTTOM DRILL DOC)
#137=.01(BOTTOM DRILL FEED)
#138=10.0(BOTTOM DRILL OUTSIDE DWELL)
#139=6.0(BOTTOM DRILL INSIDE DWELL)

IF[#105LE#110]GOTO2(SAFETY LINE)
IF[#105LE#113]GOTO2(SAFETY LINE)
IF[#140LE[#135+.1]GOTO2(SAFETY LINE)

N1(HOME)
G80G00M09
G28U0W0
M05
M01

M98P9001

N2(END PROGRAM)
G80G00M09
G28U0W0
M05
M30
Yes you get the idea. Once you get into this deeper you'll see how powerful this style of programming can be. Good job building in the safety logic. As you go you'll find your own style for what works for you. Keep it as simple and uncluttered as possible. It's good to have a template for a family of parts that includes every variable you can think of but when you save the main program to your data base I highly recommend eliminating any variable that is not needed for that specific part.
 
Yes you get the idea. Once you get into this deeper you'll see how powerful this style of programming can be. Good job building in the safety logic. As you go you'll find your own style for what works for you. Keep it as simple and uncluttered as possible. It's good to have a template for a family of parts that includes every variable you can think of but when you save the main program to your data base I highly recommend eliminating any variable that is not needed for that specific part.
yes i am liking it already. I am no where near being competent at it but I can see the potential.
 
Yes, of course.
Whether or not a better structure is possible, is a different issue.
I was adding variables as I went. I can go back and do find and replace and organize it a little better. For now I have the variables that will most likely be changing part to part at the top of the program for easier access. What else would you suggest for better structure?
 








 
Back
Top