Professional Documents
Culture Documents
Microsoft PowerPoint - Lkikstra - SW - API - Demystified - SWW08.pps
Microsoft PowerPoint - Lkikstra - SW - API - Demystified - SWW08.pps
n Programming strategies.
n Getting help.
n Available resources.
1
Benefits of learning and using. Basic Definitions
n Save time and reduce errors. n Program.
n Edit Macro
– Tools, Macro, Edit.
– Launches macro editor.
2
Macro Recorder A Look Inside a Macro File
n Records Actions n SolidWorks Objects
Visual Basic Editor – References / Type Libraries Visual Basic Editor – References / Type Libraries
n What are they? n What libraries may be needed:
3
Running a Macro – Typical Steps SolidWorks Help File
n Launch Macro. n Common
– See Also
n Attach to SolidWorks. – Example
– Availability
n Document Loaded and Type.
n Objects
– Methods
n User Form Initialization.
– Properties
– Events
n Process User Request. – Accessors
SolidWorks Examples
ModelDoc2
Why won’t some recorded macros work? Macro may not work on other computers?
n Obvious reasons: n Not so obvious reasons: n These SolidWorks settings may
affect macro performance
– SolidWorks Version. – Some selections may not have been
recorded. – Automatic Relationships
– Type Libraries.
– Macro requires preselections. – Automatic Inferencing
– Macro improperly started.
– Selected objects may not exist. – Snap to Points to Grid.
4
Make your macro work on other computers! Research
n These SolidWorks settings may n How to check for these effects n Every macro you write will require
affect macro performance some research.
– Toggle settings.
– Automatic Relationships n Visual Basic
– Re-test macro. – Online tutorials
– Automatic Inferencing – Help file
– Verify results.
– Snap to Points to Grid.
n SolidWorks
n How to bypass these effects – Learning the SolidWorks API
– SnapEnable / Snap Options.
– Document Structure
– Capture current setting. – SolidWorks API Add-Ins and Help
– Insert dimension value on creation.
File
– Change setting as needed.
– Use Fully Defined Sketches.
n Existing macros
– Change setting back.
– Anything the macro can Search for, Predict or Control. – SolidWorks Settings.
5
Progressive Learning Track Progressive Learning Track
n Intermediate ( More of a challenge ) n Advanced ( You better know your stuff )
– Refine operation of a recorded macro to work in other existing models. – SolidWorks Add-Ins. ( Run within SolidWorks environment )
n More…
6
Tips - Learn by Exploring Programming Strategies
n Look for visual clues that identify SolidWorks document structure. n Start small and work your way up
n Use variable/constant/enumeration
names that make sense
n Use existing code – SolidWorks API Help file. – Visual Basic Help file.
n Plan for multiple users or – Don’t expect help with programming – Don’t expect help with programming
distribution. techniques. techniques.
7
Resources - Examples (Users) Resources - Books
n Lenny’s SolidWorks Resources Macros, Tips, Blog n Teach Yourself Visual Basic 6 in 24 Hours
– http://www.lennyworks.com/solidworks – Author: Greg M. Perry Publisher: SAMS Publishing
– http://designsmarter.typepad.com/lennyworks/
SolidWorks API
Demystified