Front Page www.solidworks.com
   
SolidWorks Web Site Contact Us Subscribe Unsubscribe Archive
Send to a friend
 

How to automate repetitive tasks using a Show/Hide Reference Macro

Level: Intermediate
ID#: 10220522
Category:

API, Best Practice, Tech Tip

Products/Version: SolidWorks 2006
Last revised: 10/22/05



 
 

The Show/Hide Reference Macro is a good example of how VBA (Visual Basic® for Applications) can automate repetitive tasks within a 3D CAD environment. This example demonstrates the steps required to create the SolidWorks® software macro (.swp) file.

The purpose of this example is to toggle between two versions of the same design, one with and the other without Reference Geometry. This saves selecting each type of entity within the View menu. This is an example of the type of simple automation that can be done with little or no programming experience.

One method you could use to create both simple macros and more complex VB (Visual Basic) applications is to use the macro recorder to define the syntax of the API (Application Programming Interface). Instead of creating macros and programs from scratch, it is a timesaver to record a section and reuse that segment in another program. For this example, we will create the entire macro using the record function.

Create Hide.swp:
  1. Display the Macro toolbar. Select Macro from the View/Toolbars pull-down menu.
  2. Press the Record button. 
  3. Select the following entity type from the View pull-down menu:
    • Planes
    • Axes
    • Temporary Axes (optional)
    • Origins
    • Coordinate Systems
  4. Select the Stop button.  Note that the stop button is not selectable unless you are recording a macro.
  5. Name the macro's and select the macros location.
  6. Select Save to save the macro file.
Run Hide.swp:
  1. Select Play from the Macro toolbar. 
  2. Select Hide.swp. Note the system will default to your last location used for a macro. You may need to navigate (change the directory) to get to the desired location.

The final macro code created is shown below.

One addition to this application would be a comment as to the function and date the macro was created. To add a comment, edit the macro and add the line as shown below. Edit the macro and re-run the display macro.

Edit Hide.swp:
  1. Select Edit from the Macro toolbar. 
  2. Select Hide.swp.
  3. Add the following line at the top of the code. Note that a comment line will turn green after you move off the line.

    'Hide.swp created 7/15/01


  4. When complete, select Close and Return to SolidWorks from the File pull-down menu.

Once this macro has been recorded, you can attach the macro to a button using the customize function. This allows you to toggle the display state of reference geometry with one click.

It is typically a good idea to share a common macro directory located on a server within your company. That way other designers and engineers can reuse the same time-saving macros and VB applications.


 

   

SolidWorks.com
Send to a Friend
Contact Us
Subscribe to Our Newsletter
Newsletter Terms of Use

SolidWorks Corporation - 300 Baker Avenue
Concord, MA 01742 Phone: 800-693-9000
International: +978-371-5000
Copyright © 2001 SolidWorks Corporation.