Professional Documents
Culture Documents
Demystified
Leonard Kikstra
Designer / CAD Administrator
RITE-HITE Products Corporation
Milwaukee, WI
General Information
What is the SolidWorks API?
Benefits of learning/using the API.
Getting Started.
Create and modify macros.
Finding your way.
When and Why.
Program examples
Justification
Why?
Allow third party vendors to build applications that access
SolidWorks and SolidWorks data.
Lets SolidWorks focus on their core products.
Customize SolidWorks.
Add commands, change settings, etc
Access the SolidWorks API
Running a macro
Run Macro
Select macro
Macro will automatically run Run
SolidWorks Macros
Edit macro.
Select macro. Edit Macro
Visual Basic Editor automatically launched.
Make changes.
Test Macro
F5 to run macro
F8 to step thru the macro line by line
Save macro.
Exit Visual Basic editor.
New Macro
Create a new macro without using macro recorder. New Macro
Enter macro name
Visual Basic Editor automatically launched.
Visual Basic Editor:
Environment
Project:
SolidWorks Objects.
Definitions of SolidWorks Objects.
Forms.
Object based interface for user
interaction.
Custom code programmed for
each object in form.
Modules.
Modules that only contain code for
the macro.
Common modules used in many
macros.
Visual Basic Editor:
References
Access via Tools | References
menu selections in the VB
Editor.
Global
Value retained through out all modules and procedures.
Value can change
Can be used set fixed values for common reference later.
Pi = 4 * Atn(1) ' The infamous pi value
Constants
Assign a specific value to variable name.
Set once
CAN NOT be changed
CAN NOT use formula to define
Writing a macro:
Variable Types
Boolean - True or False
Multiple tiers
Parent Child relationships
Methods
Command and syntax that provides access to objects properties
Accessors
Roadmap that shows how to get to object.
Command and syntax how to get to object from parent.
SolidWorks
ModelDoc2
Writing a macro:
Routines
Sub (Procedures)
Private - Can only access
from module it resides in
Public - Can be accesses
from any module
Run from top-down until
completed
Can be access many times.
Can launch other routines.
Can pass variables between
routines.
Is a document open in
SolidWorks?
No, warn user that you need
one, then end.
Proceed
Writing a macro:
Typical Steps - User Form
User form
Preprocessing.
Set program defaults.
Read data from document.
Display user form to user.
Close macro
Macro Feature:
How To:
Rt. Click toolbar, Customize
Commands tab, Category: Macro
Drag icon and drop on toolbar.
Select an image to use on toolbar.
Fill out fields in dialog box:
Tooltip - Balloon tip at arrow.
Prompt - Help info in
status bar.
Macro - Name and full path.
Method - Module and procedure.
Shortcut - Key combo to
launch macro.
Click OK to complete
When should I write my
own macro?
Consistent retrieval & exporting of data.
Remove manual tasks and retyping errors.
Consistent results with consistent formatting.
Examples:
Retrieve and export a BOM from the assembly
No drawing required.
Create a list of all components in a directory.
Time comparison:
Time to write: 8 Hours
Automated: 1.5 Hours
Saved first use: 10-12 Hours
Time comparison:
Time to modify macro: 15 Minutes
Automated: 2.5 Hours
Saved first use: 17+ Hours
Learn by example.
Find a good macro, and study how it works.
Use [F8] in VB Editor to step thru code line-by-line.
Experiment
Write do nothing macros for Visual Basic or SolidWorks API
Learn functions you havent used before.
Develop your own functions or common routines.
Test What If scenarios.
Save your code for later use.
Help forums.
Be specific!
Repeatable problem.
Steps leading up to problem
Specific conditions lead to problem
Identify specific conditions.
Identify specific problem you are experiencing.
Dont send complete macro. Provide simple code to demonstrate.
SolidWorks API
Application Programming Interface
Presentations
Forums
May be Visual Basic Specific.
Do not be able to provide help with specific applications.