• Basic Material Properties
• User Forms
• Working with Assemblies
• Selection Manager
• Verification and Error Handling
This exercise is designed to go through the process of changing
document properties such as density. It will also review several
standard VB programming methods. This exercise could easily be
extended to copying document properties to other SolidWorks
files. It will also examine a method for parsing through an
assembly tree to change some or all of the parts in the assembly.
Part 1: Basic Material Properties
The initial goal will be to make a tool that allows he user to select
a material from a pull-down list or combo box. When he clicks an
OK button, the macro should apply the appropriate density to the
active part. The user should be able to cancel the operation
without applying a material density.
One of the limitations of recorded macros in SolidWorks is that
some dialog box actions are not recorded. At the time of
publication, material option settings were not recorded. To
automate selections in dialogs you will need to find the appropriate
method or property from the API help. This can take some
searching, so I will point out several throughout the example.
1. Create a new macro by selecting Tools, Macro, New or
2. Save it as materials.swp.
3. Declare swApp and Part publicly so they can be used in
other modules and add the code to capture the active
Public swApp As SldWorks.SldWorks
Public Part As SldWorks.ModelDoc2