Load macro from the command line

December 19th, 2008


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!

Jeff Sweeney

CSWE Engineering Data Specialist 3DVision Technologies

Loading Facebook Comments ...

6 Responses to “Load macro from the command line”

  1. Jeff Cope says:

    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. Adam says:

    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. Jeff Sweeney says:

    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. Adam says:

    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

    and

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

    but

    “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. Jeff Sweeney says:

    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. Philip Thurman says:

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

Leave a Reply

Follow
Get every new post delivered to your inbox
Join other followers
Powered By WPFruits.com
Bear