October 16, 2025

Creating Macros with SmartCAM: Part One - Macro Basics

Creating Macros in

Part 1: Macro Basics

Overview

Have you used macros before? If not, we want to make sure you know that using macros increases your productivity. It takes a bit of up-front work but using macros can assist you in completing your projects with less time and effort!

In our recent posts about saving views, we discussed adding buttons for macros. In this post, we offer you an introduction to the SmartCAM MCL (Macro Control Language) and some quick programming concepts. Macros are basically automated tasks you can tell SmartCAM to do simply by running the macro. Here are some things you can automate with macros:

  • Family of parts - a case where the you create similar parts with slight variations.
  • Common operations - a case where the you run the same operations over and over again.
  • New functionality - to give the SmartCAM application the ability to do something that it cannot already do.
  • Integration - to integrate SmartCAM with other applications.
  • Simplification - making existing functionality easier to use.

Even if you do something regularly but have changes sometimes, you can use Macros with variables so you can plug in current data and get the job done quicker. Macros are all about saving time and increasing your productivity!

This will be a three-part series. Part 1 will discuss the first steps in creating macros, part 2 discusses variables and functions, and part 3 will go over how to use them (sneak peak, there some great ways to use hot keys that save you additional time).

In this first post on the basics of creating macros, we’ll look at the following:

  • Recording a macro
  • Executing a macro (quick tip)
  • Manually creating macros/macro code fundamentals
 

Recording a macro

To create the behavior desired in the easiest possible manner, you can simply record your actions and the recording will create the macro for you. This is best for common operations that you do repeatedly. Depending on the complexity of the task and your familiarity with coding, recording may or may not be the best option. For most actions, this option is easy to complete.

Using the instructions below, let’s record a macro that makes all elements visible except the stock layer and changes the view to the top of the part (instead of the default Iso view).

We are going to start with writing out the tasks we want to perform in what is called pseudocode (What you want to do in common language – sort of. We cover this a bit more below):

Make sure everything is showing except the stock layer
    Show all
    Hide Stock layer
Switch the view
    Switch to Top view 
 

1. Start by downloading this sample test file (You will need to unzip it in order to use it).

2. Open the file MacroRecordFlangeExample.pm5 in any of your SmartCAM products.

Depending on the product you are using, you may get a compatibility warning. Click OK. This exercise will work with this file regardless of the product.

Notice that the body of the part is shades of green and Solid Model layer is red. Layers 2 and 4 are also hidden.

3. Once the part is open, go to the tool menu option Macro and select Record.

 

4. In the Macro Record window, click on the File Select button and select the location where you want to store the file and give it a name. 

Note: In order to ensure your files are not overwritten the next time you update/upgrade SmartCAM, we suggest you create a folder called “ICON” in \ProgramData\SmartCAM\Common\ and store all your custom files there.

5. Click Save and Accept.

6. Right click anywhere in the graphics view but NOT on the part, and select Show Hidden.

Notice that there are now a two green lines on the outside (one is dotted).

7. Right click on Layer 2: Stock Profile and select Hide Layer. This will hide Layer 2.

 

8. On the File Menu toolbar, go to View > Top (or simply hit the F9 key). This will switch your view to Top.

Notice that the red stock layer is now hidden from view and your part view is now from the top.

9. When you are done with all the actions, go to Macro > Stop in the toolbar.

Side Note: When you create your new macro (or use a macro), by default SmartCAM will add it to the list of recently used macros in the Macro tool list:

 

10. Go find the .mcl file you just created; you told SmartCAM where to put it in Step 4 above. Open that up in Notepad. Notice the code that was created. It should look something like this

//Product and version information
//.mcl location
//Date Created

SHOW_HIDDEN[]
HIDE_LAYER[LY=1]
DYNAMIC_VIEW[XX=1, XY=0, XZ=0, YX=0, YY=1, YZ=0, OX=0, OY=0,
OZ=0, LX=-3.13092396, RX=8.13092409, TY=0.0137514, BY=-5.0074983 

Note: two slashes (//) at the beginning or middle of the line makes the rest of that line a note and the macro will not attempt to execute anything after that until the next line 

  

Executing a macro

While waiting for our future blog to look at all the ways you can run macros (including hot keys), here is an easy way to run a macro.

11. Reload the part from the File menu. You should see it in the list of Most Recently Used files. When you go to reload it, SmartCAM will ask if you want to save the changes. Click No.

 

12. With the part reloaded, go to the Macro option on the toolbar and select Execute.

 

13. Browse to where you saved your .mcl file and click the Accept button.

 Watch while SmartCAM runs the macro and makes those changes automatically!

Here is some information about the commands in this exercise:

  • FILTER_USE turns on and off filtering of certain element types when doing a group selection.
  • SHOW_HIDDEN[] – Displays all elements.
  • HIDE_LAYER – This is the command that tells SmartCAM what layer to hide.
  • DYNAMIC_VIEW – This command resets the view to the desired view. Coordinates are based on the part, the current visible parts and the current view. This is one of those places where recording your macro makes things very simple for you…this way you don’t have to figure out all those coordinates! 
 

Manually creating macros/macro code fundamentals 

As a CNC programmer, you may be familiar with other coding languages and processes. Creating macros in SmartCAM is similar to other coding languages and is fairly simple depending on what you want to do. You saw an example of a macro above. Here are some fundamentals that also may help:

Every macro must have inputs and outputs.

  • An “input” is the information the macro needs to pull off its task.
  • An “output” is the feedback you want.
You will save yourself some time if you outline (or pseudocode) the task or tasks you want the macro to complete (including all variables and functions).
 
Try to anticipate any issues and account for them in your pseudocode. 

Here is a sample outline (pseudocode) and what the macro code would look like to count the number of elements in the current job and output that number:

Pseudocode (What you want to do in common language):
Count the number of elements in the active group
If there are no grouped elements, display one message
If there are elements in the active group, display a message with the number of grouped elements
 
Actual MCL statement:
//Count the elements
INTEGER:#numElements = GRP(0)   //Initializes the variable with # of elements in active group
//Check and see if there was anything grouped and display the appropriate message on screen
IF (#numElements < 1)
      PAUSE[TX="There are no elements currently grouped." ]
ELSE
      PAUSE[TX="There are " + ITOA(#numElements) + " elements in the active group." ]
ENDIF
 
In this case the input is the number of elements.
The output is one of the text statements.
 
The code above can be pasted into a notepad doc (or any text editor) and saved as a .mcl file 

Here is some information about those commands:

  • INTEGER claims a variable – we’ll look at variables in our next post but the short story is that it’s a holder for data you will grab later.
  • IF is a relative checker.
  • ELSE is used in case the above IF is not met (you don’t need this in all cases).
  • PAUSE puts the desired information on screen.
  • TX outputs a STRING you are looking to display.
  • ITOA converts an INTEGER to a STRING.
  • ENDIF is required to close the IF statement.
Hint: If you create a macro and when you go to execute it, it doesn’t work or you get errors, you can try parsing it down one section at a time and test each section to try to find the problematic code. 

Here is another example: Let’s say you are working on an intricate piece and you want to get a close up of just one element – in this case Layer 1. 

This is your pseudocode:

First select the Group Pick filter.
Select just Layer 1.
Zoom in by 2x with specific point at center.

In this case the inputs are the “Select” commands and the outputs are the action of selecting Layer 1 and zooming.

And here is how that would look in an actual macro:

FILTER_USE[ON=1]
LAYER_GRP[AR=0, LY="1"]
ZOOM[X1=1089, Y1=595, MF=2]

Feel free to put the above code into a .mcl file and test it. 

Here are some notes about these commands:

  • FILTER_USE toggles the group picker on or off.
  • LAYER_GRP: AR defines if you are adding or removing a layer, and LY defines the layer.
  • ZOOM: Here you add in the X and Y coordinates and MF is the multiplication factor.

The important take-away here is that while familiarizing yourself with the SmartCAM MCL feature may seem unfamiliar and daunting if you haven’t used it before, once you have the basics, the time you save with macros will be well worth it! The examples given here are pretty simple. Just like anything you can do in SmartCAM, you can dig in make these as simple or complex as you need. 

Here are some macro recipes to help get you started: https://www.smartcamcnc.com/LearnSmartCAM/current/Default.htm#recipes/macro_recipes_intro.htm?Highlight=macros

In our next post we'll cover variables (adding user input) and functions. These make your macros even more flexible and powerful. See you next month!

     



 

 


No comments:

Post a Comment