Recording custom macros in SOLIDWORKS doesn’t always require extensive knowledge of the programming language. Just like Excel, you can auto-generate the Microsoft Visual Basic code by using the macro recording tool. The Macro flyout in the Tools menu gives you access to this recorder. Click “Record” and a macro toolbar will open indicating you are recording. Any mouse clicks, menu selections and keystrokes will be recorded.
In this example, I’ve preselected two faces. When you select edges or faces while recording a macro it saves the “click” as a specific location in the model space. Therefore preselecting the faces before running the macro gives you greater flexibility as you can use the macro on many different faces or components, as long as you preselect the items before running the macro again in the future.
This is a very simple coincident mate macro. After clicking “Record”, I’ve selected Mates and added a coincident mate. Then press the Stop button to finish the recording.
You can then save the macro file (.swp extension) to your computer. Running the macro can be accomplished through the Tools > Macro menu but since macros are created for time-savings, the faster approach is to assign a keyboard shortcut or mouse gesture for quick access. In SOLIDWORKS 2011 and prior, assigning keyboard shortcuts required the macro files to be stored in a “Macros” folder in the SolidWorks installation directory. Starting in SOLIDWORKS 2012, you can now keep your shortcuts anywhere on your computer.
To assign the shortcuts, go to Tools > Customize and select the Keyboard or Mouse Gestures tab. Choose “Macros” from the Category drop-down.
Then browse for a New Macro Button. Add the location, click in the Shortcut column beside your custom macro and enter a shortcut.
Now with this macro, you can preselect two faces, press the keyboard shortcut and a coincident mate is instantly added.