Top Banner
Leonard Kikstra Leonard Kikstra Designer / CAD Administrator Designer / CAD Administrator RITE-HITE Products Corporation RITE-HITE Products Corporation Milwaukee, WI Milwaukee, WI Lenny’s SolidWorks Resources Lenny’s SolidWorks Resources http://www.lennyworks.com/solidworks http://www.lennyworks.com/solidworks SolidWorks API Demystified SolidWorks API Demystified
43

Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Dec 23, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Leonard KikstraLeonard KikstraDesigner / CAD AdministratorDesigner / CAD AdministratorRITE-HITE Products CorporationRITE-HITE Products CorporationMilwaukee, WIMilwaukee, WI

Lenny’s SolidWorks ResourcesLenny’s SolidWorks Resourceshttp://www.lennyworks.com/solidworkshttp://www.lennyworks.com/solidworks

SolidWorks API DemystifiedSolidWorks API Demystified

Page 2: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Who am I?Who am I?

Product DesignerProduct Designer– Engineering since 1982.Engineering since 1982.– CAD user/operator since CAD user/operator since

1991.1991.– SolidWorks user since SolidWorks user since

1998.1998.

CAD & PDM AdministratorCAD & PDM Administrator– 20+ people on site.20+ people on site.– Advise other sites.Advise other sites.

I want to simplifying my I want to simplifying my jobjob– Make my computer do Make my computer do

some of my work for me.some of my work for me.

SMART User GroupSMART User Group– SolidWorks user groupSolidWorks user group– Milwaukee, WI Milwaukee, WI – http://www.smart-wi.comhttp://www.smart-wi.com– Active member since 1999.Active member since 1999.

Lenny’s SolidWorks Lenny’s SolidWorks ResourcesResources– Website online Sept. 2003. Website online Sept. 2003. – New home Sept. 2006.New home Sept. 2006.

Programmed over 30 Programmed over 30 macros for use in macros for use in SolidWorksSolidWorks– Most of these are available Most of these are available

for free on the Internet.for free on the Internet.

Page 3: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is (un)covered here?What is (un)covered here?

General InformationGeneral Information– What’s a program? Objects? Macro? API?What’s a program? Objects? Macro? API?– What is the SolidWorks API?What is the SolidWorks API?– Benefits of learning/using the API.Benefits of learning/using the API.

Getting StartedGetting Started– Create and modify macros.Create and modify macros.– Variables & Constants.Variables & Constants.– Finding your way.Finding your way.– When and Why.When and Why.

Program examplesProgram examples– Justification.Justification.

Where to learn moreWhere to learn more

Page 4: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is a program?What is a program?

List of instructions.List of instructions.

– Completed in the order that they appear in program.Completed in the order that they appear in program.

– Instructions tell computer what to do and how to do it.Instructions tell computer what to do and how to do it.

– Display status and query user.Display status and query user.

– Change what to do based on changing conditions.Change what to do based on changing conditions.

– Defines what to do if a problem occurs.Defines what to do if a problem occurs.

Page 5: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is Object Oriented What is Object Oriented Programming?Programming?

Collection of objects used to define a program or data Collection of objects used to define a program or data set.set.

– Intelligent:Intelligent: Contain data that you can get access to.Contain data that you can get access to.

– Programs:Programs: Each object is capable of receiving messages, processing Each object is capable of receiving messages, processing

data, and sending messages to other objects.data, and sending messages to other objects. Portion of code is executed when object is accessed.Portion of code is executed when object is accessed. Objects can be controlled or modified within a program.Objects can be controlled or modified within a program. Objects can have attributes or properties.Objects can have attributes or properties. Some objects can contain other objects.Some objects can contain other objects.

– SolidWorks:SolidWorks: Objects can be controlled or modified by outside program.Objects can be controlled or modified by outside program. Objects can have attributes or properties.Objects can have attributes or properties. Some objects can contain other objects.Some objects can contain other objects.

Page 6: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is a macro?What is a macro?

Same as a programSame as a program

– List of instructions.List of instructions. Completed in the order that they appear in program.Completed in the order that they appear in program. Instructions tell computer what to do and how to do it.Instructions tell computer what to do and how to do it. Display status and query user.Display status and query user. Change what to do based on changing conditions.Change what to do based on changing conditions. Defines what to do if a problem occurs.Defines what to do if a problem occurs.

Dependant on “Parent” program(s)Dependant on “Parent” program(s)

– Instructs “Parent” program how to complete specific Instructs “Parent” program how to complete specific tasks.tasks.

Retrieve or modify data.Retrieve or modify data. Control “parent” program.Control “parent” program.

– Written to work within specific “Parent” program(s).Written to work within specific “Parent” program(s). Must be launched from within “Parent” program.Must be launched from within “Parent” program. ““Parent” program requires an API.Parent” program requires an API.

Page 7: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is an API?What is an API?

Application Programming InterfaceApplication Programming Interface

– An interface that consist of several sets of related An interface that consist of several sets of related functions or procedures.functions or procedures.

– Allows external programs to interact with, and control, Allows external programs to interact with, and control, the application and the data sets created by the the application and the data sets created by the application.application.

– Open SourceOpen Source

Page 8: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

What is the SolidWorks API?What is the SolidWorks API?

Application Programming InterfaceApplication Programming Interface– Allows other programs to access SolidWorks data and/or Allows other programs to access SolidWorks data and/or

control SolidWorks.control SolidWorks.– Examples: SolidWorks Add-InsExamples: SolidWorks Add-Ins

Cosmos, Toolbox, PhotoWorks, PDM Works, PDM Works Cosmos, Toolbox, PhotoWorks, PDM Works, PDM Works Enterprise.Enterprise.

Why?Why?– Allow third party vendors to build applications that Allow third party vendors to build applications that

access SolidWorks and SolidWorks data.access SolidWorks and SolidWorks data.– Lets SolidWorks focus on their core products.Lets SolidWorks focus on their core products.

SolidWorks Add-Ins have API’s.SolidWorks Add-Ins have API’s.eDrawingseDrawings SolidWorks ToolBoxSolidWorks ToolBoxFeatureWorksFeatureWorks SolidWorks UtilitiesSolidWorks UtilitiesPDMWorksPDMWorks SolidWorks RoutingSolidWorks RoutingPhotoWorksPhotoWorks

Page 9: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

How can the API benefit you?How can the API benefit you?

Automate common and repetitive tasksAutomate common and repetitive tasks– Increase productivity.Increase productivity.– Save time and money.Save time and money.– Standardize procedures.Standardize procedures.

Consistently retrieve or export data that Consistently retrieve or export data that already exists in the SolidWorks already exists in the SolidWorks documentsdocuments

Develop useful tools to meet your Develop useful tools to meet your specific needsspecific needs

Customize SolidWorksCustomize SolidWorks– Add commands, change settings, etc…Add commands, change settings, etc…

Page 10: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Access the SolidWorks APIAccess the SolidWorks API

Stand alone application Stand alone application ExecutableExecutable– Visual C++ .NetVisual C++ .Net Visual Visual

Basic .Net. Visual C++Basic .Net. Visual C++ Visual BasicVisual BasicVisual CVisual C

Programming environment outside of Programming environment outside of SolidWorks.SolidWorks.

Must be compiled to use outside of Must be compiled to use outside of programming environment.programming environment.

– Can start SolidWorks as background Can start SolidWorks as background task.task.

– Required for creating Add-Ins/DLL’s.Required for creating Add-Ins/DLL’s.

SolidWorks MacroSolidWorks Macro .swp file.swp file– Microsoft Visual Basic for Applications.Microsoft Visual Basic for Applications.

SolidWorks Program (.swp) is a single file.SolidWorks Program (.swp) is a single file. Must be launched from within Must be launched from within

SolidWorks.SolidWorks. Installed with SolidWorks.Installed with SolidWorks. No compiling necessary.No compiling necessary.

– Slower than executable.Slower than executable. Some limitations.Some limitations.

Page 11: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

SolidWorks MacrosSolidWorks Macros

The macro recorderThe macro recorder– Start macro recorder.Start macro recorder.– Complete tasks.Complete tasks.– Some changes to settings in dialog Some changes to settings in dialog

boxes are not recorded.boxes are not recorded.– Pause macro recorder if needed.Pause macro recorder if needed.– Stop recorder and save new macro.Stop recorder and save new macro.

Running a macroRunning a macro– Run Macro.Run Macro.– Select macro.Select macro.– Macro will automatically run.Macro will automatically run.

Stop Record / Pause

Run

Page 12: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

SolidWorks MacrosSolidWorks Macros

Edit macroEdit macro– Select macro.Select macro.– Visual Basic Editor automatically launched.Visual Basic Editor automatically launched.– Make changes.Make changes.– Test Macro.Test Macro.

F5 to run macro.F5 to run macro. F8 to step thru the macro line by line.F8 to step thru the macro line by line.

– Save macro.Save macro.– Exit Visual Basic editor.Exit Visual Basic editor.

New MacroNew Macro– Create a new macro (without using macro recorder).Create a new macro (without using macro recorder).– Enter macro name.Enter macro name.– Visual Basic Editor automatically launched.Visual Basic Editor automatically launched.

Edit Macro

New Macro

Page 13: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

VB Editor: EnvironmentVB Editor: Environment

Project:Project:– SolidWorks Objects.SolidWorks Objects.– Definitions of SolidWorks Definitions of SolidWorks

Objects.Objects.

Forms:Forms:– Object based interface for Object based interface for

user interaction.user interaction.– Custom code programmed for Custom code programmed for

each object in form.each object in form.

Modules:Modules:– Modules that only contain Modules that only contain

code for the macro.code for the macro.– Common modules used in Common modules used in

many macros.many macros.

Page 14: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

VB Editor: ReferencesVB Editor: References

Access via “Tools | Access via “Tools | References” menu References” menu selections in the VB Editorselections in the VB Editor

Attach objects from another Attach objects from another application to your projectapplication to your project– Standard descriptions of Standard descriptions of

object types, properties object types, properties and methods.and methods.

Selections are specific to Selections are specific to each macroeach macro

SolidWorks Type Libraries SolidWorks Type Libraries are version specificare version specific

Page 15: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: VariablesProgramming: Variables

What is a variable?What is a variable?– Temporarily data placeholder that can be used later.Temporarily data placeholder that can be used later.– Allows programmer to use a word in place of a changing Allows programmer to use a word in place of a changing

value.value.

Local variableLocal variable– Value retained only while in module or procedure where Value retained only while in module or procedure where

defined.defined.– Value can be changed.Value can be changed.– Same variable name can be defined locally in multiple Same variable name can be defined locally in multiple

modules.modules.

Global variableGlobal variable– Value retained throughout all modules and procedures.Value retained throughout all modules and procedures.– Value can be changed.Value can be changed.– Can be used to set fixed values for easy reference later.Can be used to set fixed values for easy reference later.

Pi = 4 * Atn(1) ' The infamous pi valuePi = 4 * Atn(1) ' The infamous pi value

Page 16: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: ConstantsProgramming: Constants

What are constants?What are constants?– Similar to a variable.Similar to a variable.– Assign a specific value to variable name.Assign a specific value to variable name.– Set once.Set once.– CAN NOT be changed.CAN NOT be changed.– CAN NOT use a formula to define value.CAN NOT use a formula to define value.

Page 17: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: Variable TypesProgramming: Variable Types

BooleanBoolean - True or False.- True or False.

IntegerInteger - Whole numbers only.- Whole numbers only.

LongLong - Any numerical value.- Any numerical value.

StringString - Any text based value.- Any text based value.

VariantVariant - Can be any type.- Can be any type.

Array()Array() - List or spreadsheet of data.- List or spreadsheet of data.

VariantArray()VariantArray() - List or spreadsheet of data of any type.- List or spreadsheet of data of any type.

Page 18: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: ObjectsProgramming: Objects

Must set an object to a variable to access it’s propertiesMust set an object to a variable to access it’s properties– Meta-data Meta-data - Information about object (properties).- Information about object (properties).– Features Features - Sub-objects.- Sub-objects.

Multiple tiersMultiple tiers– Parent - Child relationships.Parent - Child relationships.– Dependencies.Dependencies.

MethodsMethods Command and syntax that provides access to object’s Command and syntax that provides access to object’s

properties.properties.

AccessorsAccessors Roadmap that shows how to get to object.Roadmap that shows how to get to object. Command and syntax how to get a feature (sub-object) from Command and syntax how to get a feature (sub-object) from

parent.parent.

Page 19: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

ModelDoc2ModelDoc2

SolidWorksSolidWorks

Page 20: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: RoutinesProgramming: Routines

Sub (Procedures)Sub (Procedures)

– PrivatePrivate Can only be accessed from Can only be accessed from

module it resides in.module it resides in.

– PublicPublic Can be accessed from any Can be accessed from any

module.module.

– Run from top-down until all Run from top-down until all tasks are completed.tasks are completed.

– Can be access many times.Can be access many times.

– Can launch other routines.Can launch other routines.

– Can pass variables between Can pass variables between routines.routines.

Page 21: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: FunctionsProgramming: Functions

Special Routine / ProcedureSpecial Routine / Procedure

– Usually pass a variable to Usually pass a variable to the function.the function.

– Function returns a value Function returns a value back to the calling back to the calling procedure.procedure.

– Must be defined within Must be defined within module before subroutines.module before subroutines.

– Function can launch itself.Function can launch itself.

Page 22: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: Testing & RunningProgramming: Testing & Running

Testing macro or procedureTesting macro or procedure

– F5F5 Run macro.Run macro.

– F8F8 Step thru code line-by-line.Step thru code line-by-line.

– Start in current procedure.Start in current procedure.

Automatic starting pointAutomatic starting point

– Last procedure of the last module Last procedure of the last module inserted into the macro.inserted into the macro.

– NOT module name specific.NOT module name specific.

– NOT procedure name specific.NOT procedure name specific.

Page 23: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: Typical StepsProgramming: Typical Steps

Launch MacroLaunch Macro– Load type libraries.Load type libraries.– Set global variables and Set global variables and

constants.constants.– Attach to SolidWorks.Attach to SolidWorks.

Is a document open in Is a document open in SolidWorks?SolidWorks?– No, warn user that you No, warn user that you

need one, then end.need one, then end.

Get document typeGet document type– Wrong type, warn user and Wrong type, warn user and

end.end.

Proceed……………Proceed……………

Page 24: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: User FormsProgramming: User Forms

InitializationInitialization– Set program defaults.Set program defaults.– Read data from document.Read data from document.– Display data and form to Display data and form to

user.user.

Wait for inputWait for input– React to user input.React to user input.

Modify document.Modify document. Read more data from Read more data from

document.document. Update user form.Update user form. Update document.Update document.

– Action buttonsAction buttons OK / Process.OK / Process. Cancel.Cancel. Help.Help. Other.Other.

Page 25: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: ProcessingProgramming: Processing

Process user requests based Process user requests based on form values.on form values.

Inform user of status during Inform user of status during processing.processing.

Inform user of errors Inform user of errors encountered.encountered.

Inform user of status upon Inform user of status upon completion.completion.– Wait for user OK.Wait for user OK.

Page 26: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Programming: CompletionProgramming: Completion

Close forms.Close forms.

Clear out objects and Clear out objects and variables.variables.

Close macro.Close macro.

Page 27: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Macro Feature:Macro Feature:

Embed macro as a feature in the model.Embed macro as a feature in the model.

Overview of Macro FeatureOverview of Macro Feature– See SolidWorks API Help FileSee SolidWorks API Help File

Example by Mike WilsonExample by Mike Wilson

Page 28: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Assigning to a Toolbar Button.Assigning to a Toolbar Button.

Must have document open in Must have document open in SolidWorks to add a macro to a toolbar.SolidWorks to add a macro to a toolbar.

How To:How To:– Right-Click toolbar, CustomizeRight-Click toolbar, Customize– Commands tabCommands tab– Category: MacroCategory: Macro– Drag icon and drop on toolbar.Drag icon and drop on toolbar.– Select an image to use on toolbar.Select an image to use on toolbar.– Fill out fields in dialog box:Fill out fields in dialog box:

Tooltip Tooltip - Balloon tip at arrow.- Balloon tip at arrow. PromptPrompt - Help info in status bar.- Help info in status bar. MacroMacro - Name and full path.- Name and full path. MethodMethod - Module and procedure.- Module and procedure. ShortcutShortcut - Keyboard combination.- Keyboard combination.

– Click OK to complete.Click OK to complete.

Page 29: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

When to write your own macro?When to write your own macro?

Consistent retrieval & exporting of data.Consistent retrieval & exporting of data.– Remove manual tasks and retyping errors.Remove manual tasks and retyping errors.– Consistent results with consistent formatting.Consistent results with consistent formatting.– Examples:Examples:

Retrieve and export a BOM from the assembly.Retrieve and export a BOM from the assembly.– No drawing required.No drawing required.

Create a list of all components in a directory.Create a list of all components in a directory.

Automating common or repetitive tasks.Automating common or repetitive tasks.– Save valuable time and money.Save valuable time and money.– Examples:Examples:

Exports SolidWorks documents to different file Exports SolidWorks documents to different file types.types.

Print all drawings in the current directory.Print all drawings in the current directory. Print all drawings for all components in a Print all drawings for all components in a

current assembly.current assembly. Retrieve and export a BOM for multiple Retrieve and export a BOM for multiple

configurations.configurations.

Page 30: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

When to write your own macro?When to write your own macro?

Need to enforce compliance with standard Need to enforce compliance with standard procedures.procedures.– Provide an automated method to follow Provide an automated method to follow

standards.standards.– Consistent document appearance.Consistent document appearance.– Examples:Examples:

Preset SolidWorks settings to your company Preset SolidWorks settings to your company standards.standards.

Set annotations in document to use document Set annotations in document to use document defaults.defaults.

Copy document settings from “master” Copy document settings from “master” document to current document.document to current document.

Simplifies adding standardized notes to Simplifies adding standardized notes to drawings.drawings.

Need a special tool to automate a specific Need a special tool to automate a specific task.task.

Page 31: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Justification to write a macro:Justification to write a macro:

Define your needs.Define your needs.– What is the purpose of macro?What is the purpose of macro?– How often will you use it?How often will you use it?

The more you use it, the more time The more you use it, the more time you will save.you will save.

More use = better justification.More use = better justification.

Does it already exist?Does it already exist?– Is there something available that’s Is there something available that’s

close to what I need?close to what I need?– Can I modify something I already Can I modify something I already

have? have? – Examples files:Examples files:

Help file.Help file. SolidWorks Website.SolidWorks Website. Lenny’s SolidWorks Resources.Lenny’s SolidWorks Resources.

Page 32: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Justification to write a macro:Justification to write a macro:

Example #1 - New Macro - Document ExportExample #1 - New Macro - Document Export– Scope:Scope:

Export documents to different file types. Export documents to different file types. Drawings, Models, Configurations. Drawings, Models, Configurations. 20 models to create 300 exported files.20 models to create 300 exported files.

– Problems via manual wayProblems via manual way Repetitive, Time consuming, User input required at all steps!Repetitive, Time consuming, User input required at all steps! Selecting file type by hand every time.Selecting file type by hand every time. Consistent configuration naming.Consistent configuration naming. Did I export all configurations?Did I export all configurations? Estimate time to complete:Estimate time to complete: 12-14 Hours12-14 Hours

– Time comparison:Time comparison: Time to write:Time to write: 8 Hours8 Hours Automated:Automated: 1.5 Hours1.5 Hours Saved first use:Saved first use: 10-12 Hours10-12 Hours

– Macro can be reused many, many times.Macro can be reused many, many times.

Page 33: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Justification to write a macro:Justification to write a macro:

Example #1 – Modify Macro – Change custom property Example #1 – Modify Macro – Change custom property value.value.– Scope:Scope:

All documents require change, addition or removal of a custom All documents require change, addition or removal of a custom property.property.

1000’s of files.1000’s of files. Found macro on internet, can modify for use.Found macro on internet, can modify for use.

– Problems via manual wayProblems via manual way Repetitive, Time consuming, User input required at all steps!Repetitive, Time consuming, User input required at all steps! Did I change all documents?Did I change all documents? Did I make the right changes?Did I make the right changes? Estimate time to complete:Estimate time to complete: 20+ Hours20+ Hours

– Time comparison:Time comparison: Time to modify macro:Time to modify macro: 15 Minutes15 Minutes Automated:Automated: 2.5 Hours2.5 Hours Saved first use:Saved first use: 17+ Hours17+ Hours

– Macro can be customized and reused many, many times.Macro can be customized and reused many, many times.

Page 34: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Tips: LearningTips: Learning

Learn by exampleLearn by example– Find a good macro, and study how it works.Find a good macro, and study how it works.– Use [F8] in VB Editor to step thru code line-by-line.Use [F8] in VB Editor to step thru code line-by-line.

ExperimentExperiment– Write “do nothing” macros for Visual Basic or SolidWorks Write “do nothing” macros for Visual Basic or SolidWorks

API.API. Learn functions you haven’t used before.Learn functions you haven’t used before. Develop your own functions or common routines.Develop your own functions or common routines. Test “What If” scenarios.Test “What If” scenarios.

– Save your code for later use.Save your code for later use.

Start small and work your way upStart small and work your way up– Write and test small portions of code before continuing Write and test small portions of code before continuing

to larger portions.to larger portions.– Start with a “basic” program, then add more Start with a “basic” program, then add more

functionality and flexibility later.functionality and flexibility later.– KISSKISS: : KKeep eep IIt t SShort and hort and SSimple.imple.

Page 35: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Tips: Program CodeTips: Program Code

Add comments to your codeAdd comments to your code– Helps you and others understand what you did, and why.Helps you and others understand what you did, and why.– Helps you remember what you did or why you did it that Helps you remember what you did or why you did it that

way.way.– Identify what the routines are doing.Identify what the routines are doing.

Use existing codeUse existing code– Don’t re-invent the wheel.Don’t re-invent the wheel.– Saves time and your effort.Saves time and your effort.– Keep sample code on hand for later use.Keep sample code on hand for later use.

Know that there are multiple ways to complete tasksKnow that there are multiple ways to complete tasks– Conditional statementsConditional statements

If … Then, Else, End IfIf … Then, Else, End If - True/False- True/False Select Case …., End CaseSelect Case …., End Case - Response based on value.- Response based on value. For …. NextFor …. Next - Set number of times to - Set number of times to

do.do. Do While …. End LoopDo While …. End Loop - Don’t know how many - Don’t know how many

times.times.

Page 36: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Tips: DistributionTips: Distribution

Think about other people who may be using your Think about other people who may be using your macros.macros.

Macro may be used for needs other than initially Macro may be used for needs other than initially intended.intended.

User customization of existing macro.User customization of existing macro.– Not every user will know how to modify a/your macro.Not every user will know how to modify a/your macro.– External settings file for modifiable default settings.External settings file for modifiable default settings.

Macro defaults if settings file is not found.Macro defaults if settings file is not found.

Different companies have standards, procedures and Different companies have standards, procedures and needs.needs.

Capable of running on different versions of SolidWorksCapable of running on different versions of SolidWorks– API can check what version of SolidWorks is in use.API can check what version of SolidWorks is in use.

Page 37: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Tips: Getting HelpTips: Getting Help

SolidWorks API Help File.SolidWorks API Help File.

SolidWorks API Help forums.SolidWorks API Help forums.

SolidWorks API Support.SolidWorks API Support.– SolidWorks API functionality only.SolidWorks API functionality only.– Not for learning.Not for learning.

Be specific!Be specific!– Repeatable problem.Repeatable problem.

Steps leading up to problem.Steps leading up to problem. Identify specific conditions that lead to problem.Identify specific conditions that lead to problem.

– Identify specific problem you are experiencing.Identify specific problem you are experiencing.– Don’t send complete macro. Provide simple code to Don’t send complete macro. Provide simple code to

demonstrate.demonstrate.

Don’t expect help with programming techniques.Don’t expect help with programming techniques.

Page 38: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Resources: Tools & HelpResources: Tools & Help

Installed with SolidWorks Installed with SolidWorks – SolidWorks Application Programming Interface.SolidWorks Application Programming Interface.

– SolidWorks API and Add-Ins help file.SolidWorks API and Add-Ins help file. Explains object structure and command syntax.Explains object structure and command syntax. Many ready to use examples.Many ready to use examples. Best help file I have seen for writing macros.Best help file I have seen for writing macros.

– Visual Basic for Applications Version 6.Visual Basic for Applications Version 6. SolidWorks 2001Plus and later.SolidWorks 2001Plus and later. Visual Basic for Applications Help File.Visual Basic for Applications Help File.

– Online Tutorial - SolidWorks API.Online Tutorial - SolidWorks API. Record, Save, Edit a macro.Record, Save, Edit a macro.

Page 39: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Resources: Learning moreResources: Learning more

SolidWorks web site:SolidWorks web site:

– API programming tips and updated help files.API programming tips and updated help files.

– SolidWorks Express Newsletter - API ExamplesSolidWorks Express Newsletter - API Examples

– Download projects, sample programs and macros.Download projects, sample programs and macros.

– SolidWorks Developer Kit. (SDK)SolidWorks Developer Kit. (SDK) Not required.Not required. Contains working sample programs.Contains working sample programs. New SDK for each version of SolidWorks.New SDK for each version of SolidWorks.

– Presentations.Presentations.

Local VAR / SolidWorks Reseller.Local VAR / SolidWorks Reseller.

– SolidWorks API Training classes.SolidWorks API Training classes.

Page 40: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Resources: SolidWorks API Resources: SolidWorks API ExamplesExamples

Lenny’s SolidWorks ResourcesLenny’s SolidWorks Resources Macros, Tips, Macros, Tips, BlogBlog– http://www.lennyworks.com/solidworkshttp://www.lennyworks.com/solidworks

Mike Wilson’s SolidWorks Modeling TechniquesMike Wilson’s SolidWorks Modeling Techniques Macro FeatureMacro Feature– http://www.mikejwilson.com/solidworks/solidworks_files.htmhttp://www.mikejwilson.com/solidworks/solidworks_files.htm

Matt LombardMatt Lombard MacrosMacros– http://mysite.verizon.net/mjlombard/http://mysite.verizon.net/mjlombard/

Joe Jones at New Hampshire CADJoe Jones at New Hampshire CAD TutorialsTutorials– http://www.nhcad.com/sw_macros/index.htmlhttp://www.nhcad.com/sw_macros/index.html

Stefan Berlitz’s SolidWorks ToolsStefan Berlitz’s SolidWorks Tools MacrosMacros– http://www.swtools.de website.http://www.swtools.de website.

SolidWorks Tips & ThingsSolidWorks Tips & Things API TipsAPI Tips– http://www.solidworktips.com/http://www.solidworktips.com/

Page 41: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Resources: Visual Basic Resources: Visual Basic ProgrammingProgramming

WebsitesWebsites– ““Tutorial” and “Lessons”Tutorial” and “Lessons”– May be Visual Basic Specific.May be Visual Basic Specific.– Do not provide help with specific applications.Do not provide help with specific applications.

ForumsForums– May be Visual Basic Specific.May be Visual Basic Specific.– May not be able to provide help with specific May not be able to provide help with specific

applications.applications.

Search - Too many to list.Search - Too many to list.

Some provide better explanation and examples.Some provide better explanation and examples.

Page 42: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

SolidWorks User Group Network (SWUGN)SolidWorks User Group Network (SWUGN)

Richard DoyleRichard DoyleSolidWorks Community CoordinatorSolidWorks Community Coordinator

SWUGN Committee ChairmanSWUGN Committee Chairman

Wayne TiffanyWayne TiffanyPresident, Kansas City SolidWorks User GroupPresident, Kansas City SolidWorks User GroupSWUGN Committee Member – Southern USASWUGN Committee Member – Southern USA

Thank you!Thank you!

Page 43: Leonard Kikstra Designer / CAD Administrator RITE-HITE Products Corporation Milwaukee, WI Lenny’s SolidWorks Resources .

Your questions?Your questions?

This presentation and handout of slides can be This presentation and handout of slides can be downloaded from:downloaded from:

Lenny’s SolidWorks Resources:Lenny’s SolidWorks Resources:http://www.lennyworks.com/Solidworks