Custom Macros Can Skip Holes After Replacing Broken Tools
Using “vacant” local variables enables CNC machinists to create custom macros that can target multiple types of machining work.
Share






Some programmers shy away from using custom macros because they feel these macros make it more difficult to restart a program from the middle of a complex machining operation. This concern can often be overcome with a little planning. Indeed, custom macros sometimes make it easier to restart the program and run from the middle of a cutting tool’s machining operation.
The technique in this article was inspired by Chad Kluth of in Kaukuana, Wisconsin. I was helping him resolve a different issue in a bolt-circle hole-machining custom macro. I include it here since it is relevant to our discussion.
Kluth’s application involved machining very large and tough 4140 steel components used in the mining industry. He needed to drill as many as 100 holes, each 2 inches in diameter, around a bolt-circle pattern into a round face/flange to a 6-inch depth. As you can imagine, tool wear and tool breakage are big issues. Even a drill with new inserts may not make it all the way through the cycle without wearing out — and the drill could be 90 holes into the cycle when it does wear out. To make matters worse, a hard inclusion in the raw material could cause the drill to break at any time.
Kluth uses a universal bolt-circle custom macro capable of performing several kinds of hole-machining operations, including drilling, standard tapping, rigid tapping, reaming and counterboring. The original issue had to do with rigid tapping. Being a “universal” custom macro, the M29 command needed to ignore rigid tapping if the machine was performing any other operation. To solve this issue, we used “vacant” local variables.
As for skipping holes, an argument in the calling command specifies the number of holes to skip. For example, if the drill wears out during the 90th hole, the user needs to set this argument to 89. We used the K-word (L-word with older FANUC CNCs) in the canned cycle command to specify whether the machine should skip a hole. If K is set to zero (K0), the hole is skipped. If K is set to one (K1), the hole is machined.
Here is a sample program containing an example calling command:
- O0001
- N005 G90 S500 M03
- N010 G00 X0 Y0
- N015 G43 H01 Z0.1
- N020 G65 P9010 X0 Y0 Z0 C81.0 D6.0 R0.1 B12.0 A90.0 I100.0 F12.0 H89.0
- N025 G91 G28 Z0
- N030 M30
These are the mandatory arguments that must be in the calling command:
- (X = X center)
- (Y = Y center)
- (Z = Z surface)
- (D = Hole depth)
- (C = Cycle to use — G81, G82, G83, G73 or G84)
- (R = Z rapid position)
- (B = Radius of bolt circle)
- (A = Start angle)
- (I = Number of holes)
- (F = Feed rate)
These are the arguments that are only required in special cases:
- (T = Needed with G82 to specify dwell time)
- (Q = Needed with G73 or G83 to specify peck depth)
- (M29.0 = Needed if rigid tapping)
- (Sxxxx.x = Needed if rigid tapping to specify spindle RPM)
- (H = Needed if skipping holes to specify the number of holes to skip)
Here is the custom macro:
- O9010 (Universal bolt-circle custom macro)
- #101=1 (Initialize counter)
- #102=#1 (Initialize current angle to A)
- #103=360 / #4 (Incremental angular distance between holes)
- #104=#26 + 0.1 (Rapid approach plane)
- #105=#26 - #7 (Z bottom position of hole)
- #32=1 (Skip-hole counter — used if H is included in calling command)
- N1 IF[#101 GT #4] GOTO 99 (Test if finished machining holes)
- #110=#24 + COS[#102] * #2 (X position for current hole)
- #111=#25 + SIN[#102] * #2 (Y position for current hole)
- #33=1 (K word value, set to 1 in case next hole will be machined)
- IF[#11EQ#0] GOTO5 (Test if H is included in the calling command)
- IF[#32GT#11] GOTO5 (Test if finished skipping holes)
- #33=0 (Next hole will be skipped)
- N5 M#13 S#19 (Not executed if #13 and #19 are vacant)
- G#3 X#110 Y#111 R#104 Z#105 P#20 Q#17 F#9 K#33 (Machine current hole)
- G80 (Cancel cycle)
- #101=#101 + 1 (Step counter)
- #102=#102 + #103 (Step current angle)
- #32=#32+1 (Step skip-hole counter)
- GOTO 1 (Go back to test)
- N99 M99 (End)
Here is a guide to the bolded items in the custom macro:
- M#13 S#19 – If a CNC word contains a vacant local variable, the CNC will ignore the word. When performing rigid tapping, the calling command must include the words M29.0 and Sxxxx.0 (S specifies the RPM for rigid tapping). If doing some other operation, users must leave M and S out of the calling command.
- P#20 and Q#17 – If the user is using counterboring (G82), they must include T in the calling command to specify dwell time. When peck drilling (G73 or G83), users must include Q to specify peck depth.
- K#33 – FANUC has two programming formats for canned cycles. With newer FANUC CNCs, K specifies the number of holes being machined. Older FANUC CNCs use L for the same purpose. If this custom macro does not work (the machine is not skipping holes even if H is included in the calling command), change the K#33 in this command to L#33.
Related Content
4 Commonly Misapplied CNC Features
Misapplication of these important CNC features will result in wasted time, wasted or duplicated effort and/or wasted material.
Read MoreOrthopedic Event Discusses Manufacturing Strategies
At the seminar, representatives from multiple companies discussed strategies for making orthopedic devices accurately and efficiently.
Read MoreSetting Up the Building Blocks for a Digital Factory
Woodward Inc. spent over a year developing an API to connect machines to its digital factory. Caron Engineering’s MiConnect has cut most of this process while also granting the shop greater access to machine information.
Read MoreContinuous Improvement and New Functionality Are the Name of the Game
Mastercam 2025 incorporates big advancements and small — all based on customer feedback and the company’s commitment to keeping its signature product best in class.
Read MoreRead Next
Machine Shop MBA
Making Chips and 91ÊÓÆµÍøÕ¾ÎÛ are teaming up for a new podcast series called Machine Shop MBA—designed to help manufacturers measure their success against the industry’s best. Through the lens of the Top Shops benchmarking program, the series explores the KPIs that set high-performing shops apart, from machine utilization and first-pass yield to employee engagement and revenue per employee.
Read MoreLast Chance! 2025 Top Shops Benchmarking Survey Still Open Through April 30
Don’t miss out! 91ÊÓÆµÍøÕ¾ÎÛ's Top Shops Benchmarking Survey is still open — but not for long. This is your last chance to a receive free, customized benchmarking report that includes actionable feedback across several shopfloor and business metrics.
Read MoreAMRs Are Moving Into Manufacturing: 4 Considerations for Implementation
AMRs can provide a flexible, easy-to-use automation platform so long as manufacturers choose a suitable task and prepare their facilities.
Read More