Load macro from the command line


My Great Aunt Eleanor loves to write code that uses SolidWorks’ event handler.  ..but with all of that compiling and .dll registration she often complains “dag-gummit ” it would be easier to just write a SOLIDWORKS macro.

While it is true that macros (.swp files) can watch events. I have never seen much value in doing so – because the macro needs to be loaded to work …and I always forget to load the macro. Thus whenever I wanted to watch events, I have always just written an addin -SOLIDWORKS addins can be set to load automatically.

My buddy Jeff Cope* showed me how to load a macro via the command line at SOLIDWORKS start up.

SW Shortcut

  1. Create a shortcut to your SOLIDWORKS executable [“C:\Program Files\SOLIDWORKS Corp\SolidWorks\SLDWORKS.exe”]
  2. Right mouse button click on your new SOLIDWORKS shortcut and select Properties.
  3. In the properties dialog for the shortcut, append the “target” property (located on the Shortcut tab) to include “/m” followed by a space then the full path to the macro in quotation marks. It should look something like this:

Command Line

Now your macro will be loaded and run when you start SOLIDWORKS, and you can watch events with a macro. Now Great Aunt Eleanor will have more time available to play Wizards of Warcraft.

*Even the mighty Engineering Data Specialist man is not above being a name dropper!

6 comments on “Load macro from the command line

  1. Thanks for giving me credit. I have to turn around and give credit to my good buddy Rodney Hall who showed me : )

    I think he, in turn, looked it up on those darn internets.

  2. Hi Jeff,

    Anyway to force the macro to act on a file using this method?

    i.e. Load a file into SOLIDWORKS from the command line and have it run a macro once the file is loaded?

  3. Sure! That is the cool thing about it. That macro will stay in memory the entire time the SW session is running.

    This means that macro could be sitting there dormant waiting for a certain event to happen. (in your example a file is opened) Once the event happens the macro can fire and do anything you want!

  4. Yes, but is there a way to load a file and macro at the same time from the command line?

    For example:

    “path to sldworks.exe” “path to swx file” will open the SWXfile


    “path to sldworks.exe” /m “path to macro” will load the macro


    “path to sldworks.exe” “path to swx file” /m “path to macro” won’t load the file, then run the macro on that file.

    Any ideas?

  5. That isn’t surprising, a command line only knows to look for so many arguments.

    Perhaps your macro could open the file? …or your macro looks for a text file containing a list of files to work on?

  6. Using the startup macro…can you pop a static message to the user like “open your files from the network P drive”

Comments are closed.