CNC Macro Programming with Fanuc Macro B

Last modified: March 13, 2024

CNCCookbook’s G-Code Tutorial

What is CNC Macro Programming?

You have not provided any text to be rephrased. Please provide the text you would like rephrased.

The evolution of machine programmabilty...

The next several lessons in the g-code tutorial provide a Mini-Tutorial on CNC Macro Programming and Fanuc Macro B. In many ways, Macro Programming is the highest level of G-code Programming. It offers the most flexibility and the greatest potential power of any of the G-Code Programming Techniques.

Without CNC Macro Programming, G-Code is not really a full fledged computer language, it's more a recording of a series of manual steps. That's useful, but computers and CNC controllers are capable of a lot more.

With CNC Macro Programming, a vast number of new things are possible.  We've prepared an article, 37 Things Your CAM Won't Do For You That GCode Programming Can, that tells all about the potential things you might do with CNC Macro Programming.  Here are just a few ideas from the article:

There are many more examples in the article, but you get the idea how powerful CNC Macro Programming can be.  Go through our lessons so you can add this power tool to your tool box.

A word about Fanuc Macro B

Fanuc Macro B is by far the most common Macro Programming Dialect. Not all controllers support full Macro B, and there are variations supported by some non-Fanuc controllers. We can't document every G-Code Dialect here, but the concepts offered in Macro B will be similar to what you see elsewhere, and therefore applicable to those cases with slightly different syntaxes and capabilities. If you don't have a controller with Macro B, it's still worth checking it out. Just use a our G-Wizard CNC Simulator and Editor to play with the Macro B capabilities.

CNC Macro Programming Topic Areas

CNC Macro Programming may be broken down into the following topic areas, and we have a lesson for each area:

Let's give a brief overview of what each one means and how they fit together, then we'll turn you loose to go through each lesson in more detail.  But before we do that, let me tell you about a tool that will help you tremendously in learning and in doing CNC Macro Programming.

Click to get a free trial of G-Wizard Editor: It makes G-Code easy!

G-Wizard Editor for CNC Macro Programming

CNC Macro Programming makes for more complex g-code.  As such, any tool that will make it easier to understand what the g-code is doing and even to test it by simulation before you put it on your CNC machine is very helpful.

Our G-Wizard Editor is the perfect tool for anyone wishing to do CNC Macro Programming.

Here's just a smattering of the specific features it has that are a tremendous help when CNC Macro Programming:

Software interface with green and red 3D model/blueprint displayed.

Control panel interface with pause, rewind, fast forward, and playback speed buttons.

Change speed, jump ahead to the interesting parts, rewind to see it again, vary playback speed, and more.

Computer screen with gray background and grid pattern, showing multiple windows displaying data: graph trend, machine parameters (spindle speed, feed rate), and programming options.

Click to get a free trial of G-Wizard Editor: It makes G-Code easy!

Parameterized Programming

Parameterized programming is all about using variables in g-code programming.  With variables, you "parameterize" your cnc program, making it much more flexible.  For example, let's say you've got a program designed to create up to 8 parts on a fixture plate.  You might include a parameter or variable at the top of the program that tells how many parts are really loaded.  This makes it possible for the same program to work on any number of parts from 1 up to the 8 of a full fixture plate.

Or, perhaps you want to parameter some dimension on a part.  Again, by setting up a variable to control the dimension, you can easily use the same g-code program to do a lot of different things.

[ Read Our Training Lesson on CNC Parameterized Programming ]

Subprograms and Macros

Let's say you've created a valuable g-code program and you want to use it over and over, sharing it among various other g-code programs.  A shared piece of g-code like that is called a "Subprogram", and it's very easy with CNC Macro Programming to manage subprograms.

[ Read Our Training Lesson on Subprograms and Macros ]

Conditions and Looping

Sometimes, you want the g-code to do different things under different conditions.

Take our deep hole custom cycle example.  We've got a g-code subprogram that does all sorts of smart things to enable it to drill very deep holes automatically.  But, we don't need to do all those smart things on shallow holes.  In fact, the shallower the hold, the less smart we need to be.

So, we can put condition tests into the routine that take a macro variable for hole depth and decide how fancy to get based on how deep the hole is.

[ Read Our Training Lesson on Fanuc Macro B Conditions and Looping ]

If you've been following our GCode Course up to this point, you know that gcode is very modal.  It remembers things that happened earlier in the part program.

In this chapter, we'll teach you how your macros and subprograms can know those things that happened in the past and potential act on them.

[ Read Our Training on Accessing Modal Data ]

This lesson is still in development and we hope to have it available for you soon!

Detailed Macro Example: Digits

[ Read the Digits CNC Macro Programming Example ]

More CNC Macro Programming Resources

For a deeper look into more advanced macro programming, I recommend Peter Smid's book, CNC Custom Macros:

Gray and yellow book cover with "FANUC CNC Custom Macros" in light blue font.

Be the first to know about updates at CNC Cookbook

Join our newsletter to get updates on what's next at CNC Cookbook.