跳到主要内容

Recording and Editing SOLIDWORKS Macros

SOLIDWORKS provides a great feature to record user actions and convert them into macro code.

This is a very convenient feature for learning SOLIDWORKS API and finding the desired methods.

You can start recording by clicking the Record button on the macro toolbar:

Macro Record Command in the Toolbar

In recording mode, most user actions will be recorded.

Note: Not all commands can be recorded using macro recording. If a command is not recorded, it does not mean that the API for that particular command is unavailable.

To enhance the macro recording experience, try to minimize changes in the model view orientation and selections, as these commands will be recorded and can make the macro code difficult to read due to a large number of lines.

Use the Pause button to skip unnecessary action recordings.

Once the recording is complete, click the Stop button and choose the file to save the recorded macro.

Save Recorded Macro{ width=400 }

Note that macros can be saved in both VBA and VSTA formats. Refer to the Macro Types article to understand the differences between these macro types.

If you frequently record macros, it is recommended to enable the Edit macro after recording option.

Option to Automatically Edit Macro{ width=350 }

This way, the editor will automatically open after macro recording is finished, eliminating the need to explicitly call the Tools->Macro->Edit menu command to edit the source code.

Here are example macros recorded using VBA, C#, and VB.NET languages:

Example Macro Recorded in VBA{ width=350 }

Example Macro Recorded in C# VSTA{ width=350 }

Example Macro Recorded in VB.NET VSTA{ width=350 }