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

Create Custom Programs and Macros for SolidWorks



 
 

Both VB and C++ can be used to create executable (exe) programs that can be run inside, and interact with, SolidWorks® software. VB (Visual Basic®) and VBA (Visual Basic for Applications) allow all levels of programmers, especially novice programmers, to easily create programs that automate common functions and extend the capabilities of SolidWorks using the SolidWorks API (Application Programming Interface). The example VB application provided is well commented to help novice programmers create customized versions of the application.

The custom properties VB program that was made available in last month's issue is an example of a simple VB application. To modify and recompile this application requires Microsoft®? Visual Basic 6.0 or higher.

This section lists some general programming practices that will make creating, maintaining, and modifying applications easier. Before starting, read the following good programming practices and tips:

  • Review the code within Visual Basic. Each section of the code is commented to help novice programmers understand what is happening. Placing comments within code is a good idea even if you are the only person to modify the program. It does not take long to place a simple comment in the code, it helps make the program more legible, and it makes the program easier to modify in the future. To comment a line of code, just place a ' in front of the line and the rest of the line is ignored by VB. The color of the line will change, as shown in the example below.

    '******************************************
    Ver 1.0 CustomProps
    ' This app will set custom property values for parts, assemblies,
    ' and drawings without using the built-in properties dialog box.
    '******************************************

  • Add a header to the code that describes changes. List who made the change, a brief description, and the date or version number. The latest file modified date is not a good tool for version control for an application.
  • Always make a copy of a working program before making modifications. This way, if you make a mistake, you can always go back and refer to the original code. Professional programmers typically use PDM-like software vault software versions.

The CustomProps application is made up of the following files:

  • custom_props.exe—The compiled version of the project file. After making changes to the project the executable needs to be recompiled. This is done in VB by selecting Make model_prop.exe from the File pull-down menu. The compiled version can be separated from the other VB files listed below.
  • custom_props.vbp$#151;The Microsoft Visual Basic project file. This project file contains the preceding files and is compiled to make custom_props.exe. By double-clicking this file, the Visual Basic project file is opened.
  • model_props.frm$#151;This is the main form and code for this application. All modifications will be done to this object.
  • frmAbout.frm$#151;Relates to the application form. Displays the version number of the application.
  • swconst.bas$#151;This is a SolidWorks-supplied constants file that is included as a module. The user does not change this module.

The following image shows the Visual Basic Project Explorer for the custom property application. Double-clicking on the object opens the form or code. The left and center buttons can be pressed to display the code or the object (form). The form is the visual user interface portion of the application. The code is the programming portion of the object.

How to Customize the CustProps Project

  1. Create a copy in a different folder of the files listed above. >Review your standard templates to insure they already have the custom properties defined.
  2. Review the custom properties listed in the file model_props.frm. This dialog box is displayed under the Project Explorer window in VB.
  3. Modify the form and code in the file model_props.frm using Visual Basic.
  4. Compile the program by selecting Make custom_prop.exe from the File menu. If there are errors, fix these and recompile.

A basic understanding of the API and VB allows novice programmers the ability to create new macros and programs. This is a powerful tool for automating non-value-added processes within your company.


 

   

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.