SolidWorks API Help

Table of Contents

How to Add a Custom Macro as an Add-In to the SolidWorks CommandManager?

Steps to Add a Custom Macro to the CommandManager:

  1. Ensure the Macro is Ready
    • Create your macro file using SolidWorks VBA Editor or another supported editor.
    • Save it as a .swp file in a known location.
  1. Open the Customize Menu
    • Go to ToolsCustomize… (or right-click on the CommandManager and select Customize).
  1. Access the Macro Button Option
    • In the Customize dialog, go to the Commands tab.
    • Scroll down to the Macro category.
  1. Drag the Macro Button to a Tab
    • Drag and drop the “New Macro Button” onto the desired tab in the CommandManager (e.g., Features, Sketch, or a custom tab).
  1. Assign Your Macro
    • Right-click on the newly placed button and select Edit Button.
    • In the Edit Command dialog:
    • Click Browse… next to the Macro File field and select your .swp file.
    • If your macro contains multiple subroutines, specify the desired Macro Button.
  1. Customize Button Appearance

In the same Edit Command dialog:

    • Set the Tooltip (description of the macro functionality).
    • Add a button icon: Use a pre-existing SolidWorks icon or create your own (e.g., a .bmp file with dimensions of 20×20 pixels for small and 40×40 pixels for large).
  1. Test the Macro Button
    • Exit the Customize dialog.
    • Click your newly added button to test its functionality.

Optional: Group Macro Buttons

  • If you have multiple macros, consider creating a custom CommandManager tab to group them.
  • In the Customize menu, go to the Toolbars tab and create a new toolbar. Then, drag your macro buttons onto it.