CODE YOU CAN BUILD ON
SOLIDWORKS macro library.
Practical examples for the tasks you do every day. Browse by topic or find the API call you need.
372 examples20 topicsFree access · No account required
Automation / Tools / Utilities
18 examples- Apply All Dimension Values to All Configurations
- Change sketch dimensions via user form
- Close all documents except drawings
- Create 3D points from data in Excel or text file
- Create configuration for each body
- Display selected component's custom properties
- Equation-Triggered Macro Utility
- Error logging using FileSystemObject
- Get all SolidWorks models in a folder
- Get name, owner, type, position, and value of all dims on sheet
- Involute Spur Gear Creator
- Is body a 2D body
- Keep VBA user form on top on 64 bit systems
- Save all parts in a folder as parasolid
- Save Document Utility
- Save out all part components with specified extension
- Save out sheets as individual drawings
- Toggle document's unit system between MMGS and IPS
Assemblies
29 examples- Add mate to selected entities
- Add width mate
- Assembly automation example - with transforms
- Assembly automation example - without transforms
- Automate mating with mate references
- Change configuration of selected component
- Delete all missing components
- Delete part from sub-assembly
- Delete specific folder and its components
- Demonstrate of safe entities
- Dissolve all component library features in assembly
- Dissolve all sub-assemblies
- Edit the alignment of a mate
- Get assembly's maximum depth
- Get belt length and add to belt component's custom properties
- Get component mass properties
- Get IFeature object from component
- Get mate information
- Get named entities in a component
- Get the feature information for a component
- Insert a new part in a sub-assembly
- Insert components at a specific location using transforms
- Is component from design library
- Isolate parent sub-assemblies of selected components
- Referenced configuration example
- Rename assembly component from feature tree
- Run code on every part in assembly
- Save virtual components to external file
- Toggle component lightweight / suppressed state
Custom properties
7 examples- Change BOM quantity in custom properties
- Copy drawing custom properties to part or assembly
- Copy part or assembly cust. props. to drawing cust. props.
- Demonstration of important custom properties methods
- Export model's custom properties to Excel file
- Get all custom property names and values
- Move all configuration specific custom properties to document custom properties
Drawings
41 examples- Add callouts to all hole wizard holes
- Change all layer colors
- Change layer of selected annotations
- Change the dimension colors in selected view
- Delete a drawing sheet
- Delete all blocks from current sheet
- Delete and re-add revision table
- Delete balloons attached to fasteners
- Explode the selected block
- Export all drawing sheets to a single PDF
- Find text in blocks made from notes
- Flip visibility of all blocks in a drawing
- Get a view's orientation using transforms
- Get and set dimension text
- Get BOM table on specific drawing sheet
- Get cell data in active sheet's table
- Get center mark's owning edge
- Get components in selected drawing view
- Get current sheet number
- Get drawing note bounding box
- Get IEntity pointer for entity selected in drawing view
- Get polylines information
- Get selected bend line's owning flat pattern feature
- Get the edges used by a dimension
- Get the names of all sheets and drawing views
- Get the position of a view
- Get the text and custom property link of a note
- Get types of display dimension
- Insert block at specific location
- Insert broken view and set break line positions
- Insert hole table using selected vertex
- Insert top-level only BOM
- IView::GetXform vs IView::GetViewXform
- Move BOM to a different sheet
- Relocate view to true center after extents are modified
- Renaming sheets
- Save selected table as Excel spreadsheet
- Search and replace title block notes
- Search for and hide components in drawing views
- Select the edges in a drawing view
- Set the name of a note
Features
16 examples- Accessing and releasing feature data
- Create a circular pattern feature
- Create an extrude from a sketch
- Create axes through points normal to plane
- Demonstration of important IFeature members
- Determine whether feature is suppressed
- FeatureManager traversal
- Get the features used to create a fillet
- Get the parent sketches of a selected feature
- Mirror part and save out result
- Modify feature data in a component
- Modify feature data of an extrusion
- Modify fillet size
- Modify filleted entities using adjacent edges
- Modify filleted entities using pre-selection
- Modify filleted entities using traversal
Macro features
2 examplesEvent notifications
11 examples- Cancel save if part wasn't modified using notifications
- Determine whether new or existing file was opened
- Drawing sheet change event nofication example
- Kill listener class after event notification fires
- Listen for mouse events
- Message user upon application exit using notifications
- Notification when SolidWorks is idle
- Notify user when a specific feature is created
- Post-rebuild event notification example
- Rename solid bodies after rebuild
- Save component after dropped from task pane
Opening and saving documents
4 examplesParts Only
23 examples- Add or find attributes on all faces
- Add, subtract, or combine two selected bodies
- Autosize all reference planes in active part
- Color hole wizard feature after creation
- Configure dimension according to user input
- Create extruded base with user form
- Create linear pattern in two directions
- Delete BOM table from part
- Delete global variable and all associated equations
- Find dimension by name
- Get body's owning feature
- Get face that owns cosmetic thread
- Get loft pick points
- Get or set dimension value in a part while in drawing or assembly
- Get sketched outline / projection of part
- Insert axes concentric to cylindrical faces of selected feature
- Insert split feature
- Keep largest body and delete the rest
- Print values of all sketch dimensions
- Run geometry analysis
- Select all faces with same color as pre-selected face
- Traverse body features and make dimensions read-only
- Update config listed in external references of inserted part feature
Appearances and Materials
12 examples- Change selected body's material in all configurations
- Get material database XML
- Get material of selected component
- Modify all existing appearances in a part using IRenderMaterial
- Remove all part appearances using IRenderMaterial
- Remove appearance of selected object using IDisplayStateSetting
- Set or remove material from a part or selected body
- Set or remove selected object appearance using that object's members
- Set selected object's .p2m appearance file using IRenderMaterial
- Set selected object's appearance using IDisplayStateSetting
- Set selected object's color using IRenderMaterial
- Working with display states
PropertyManager pages
3 examplesSelection
8 examples- Determine whether selected faces are parallel
- Get hole wizard feature used by selected hole callout
- Select a face using IModelDoc2::SelectByRay
- Select an entity by its name
- Select component body feature using IModelDocExtension::SelectByID2
- Select the loops adjacent to selected face using co-edges
- Set selection color
- Sketch contour selection
Sketching
12 examples- Change driven / driving state of selected dimensions
- Create a keyhole profile and then extrude cut
- Create acute angular dimension
- Create points at a curve's intersections
- Delete sketch relations and fully define sketch from origin
- Find a specified sketch point
- Get diam of circle sketch seg used to create selected feature
- Get sketch entity name
- Get start and end points of sketch segment
- Get the coordinates of all sketch points in a drawing view
- Get the number of entities in selected sketch
- Transform sketch points from sketch to model coordinates
Bounding Boxes
4 examplesTransforms
10 examples- Align component to assembly origin and default planes
- Align components' origins and default planes
- Get mate information for selected component
- Get the normal data for a face
- Get the normal value in relative to assembly
- Rotate a component about an axis using ArrayData
- Rotate a component about an axis using IDragOperator
- Rotate a component using ArrayData - another example
- Rotate component using SetData
- Translate component using ArrayData
Traversing and locating objects
20 examples- Assign and find tracking IDs
- Get diameter of largest circular edge in body
- Get distance between two largest planar faces in a body
- Get largest face in a body
- Get longest edge in a body
- Get longest sketch segment in a sketch
- Get the edges attached to a vertex
- Get the length, start point, and end point of an edge
- Mark and select fillets under a certain radius
- Re-select entities using persistent IDs
- Renaming entities
- Select edges adjacent to selected edges use co-edges
- Setting and getting faces by name
- Setting and getting vertices by name
- Test whether edges on a body are straight or curved
- Traverse components - simple
- Traverse components in order
- Traverse features in order using recursion
- Traverse notes and change their text
- Traverse sketch segments while adding dimensions
Weldments and Sheet Metal
11 examples- Change sheet metal feature k-factor
- Delete all bodies except first body in cut list folder
- Disable automatic cut list updating
- Display custom properties for selected cut list folder
- Export flat pattern as DXF
- Export sheet metal flat pattern to specified location
- Get selected weldment body's cut list feature
- Get weldment bodies
- Get weldment profile and cut list custom properties
- Toggle sheet metal bend notes
- Toggle sheet metal flat pattern on and off
Other
23 examples- Add and read attributes on document
- Change system settings
- Change table cell text color
- Copy table to clipboard
- Create columns of text with monospaced fonts
- Create pack and go with specified custom property as prefix
- Find intersecting edges between two bodies
- Get SolidWorks version
- Get text from BOM table cells
- Is body created at angle / off-plane
- Isolate selected body
- IUserProgressBar demo
- Merge temporary bodies
- Move mouse cursor to selected point
- Pack and go to folder
- Pack and go top level parts only
- Read, add, delete, and modify equations
- Replace referenced entity in reference plane
- Return swSelectType_e name for selected object
- Run individual SolidWorks commands
- Run macro from another macro
- Run macro from Design Binder
- Suppress all folders in model with specified name
VBA Language
12 examples- Class example using collection
- Class example using SolidWorks object
- Collection example
- Debug.assert example
- Enable command button depending on combo and text box state
- Enumeration example
- Error handling example
- Function example
- Implements example
- Public vs Dim declaration example
- Switch example
- User-Defined Types example
More examples
106 examples- Display user form on part open using ETM
- Explode all sketch blocks in all drawing sheets
- Increase ambient lighting
- Lesson 1.10 code
- Lesson 1.10 homework solution
- Lesson 1.10 start code
- Lesson 1.2 homework solution
- Lesson 1.3 code
- Lesson 1.3 homework solution
- Lesson 1.4 - select case code
- Lesson 1.4 homework solution
- Lesson 1.5 - for - next loop code
- Lesson 1.5 - loop examples code
- Lesson 1.5 homework solution
- Lesson 1.6 - data conversion functions
- Lesson 1.6 - date and time functions
- Lesson 1.6 - InputBox function
- Lesson 1.6 - MsgBox function
- Lesson 1.6 - replace function
- Lesson 1.6 - split function
- Lesson 1.6 - string functions
- Lesson 1.6 homework part A solution
- Lesson 1.6 homework part B solution
- Lesson 1.6 homework part C solution
- Lesson 1.7 - ByVal vs Byref
- Lesson 1.7 - classes
- Lesson 1.7 code
- Lesson 1.7 homework part A solution
- Lesson 1.7 homework part B solution
- Lesson 1.7 homework part C solution
- Lesson 1.7 start code
- Lesson 1.8 code
- Lesson 1.8 homework solution
- Lesson 1.9 code
- Lesson 1.9 homework solution
- Lesson 1.9 homework start
- Lesson 1.9 start code
- Lesson 2.2 code
- Lesson 2.2 homework part A solution
- Lesson 2.2 homework part B solution
- Lesson 2.3 - API object model
- Lesson 2.3 homework part A solution
- Lesson 2.3 homework part B solution
- Lesson 3.1 code
- Lesson 3.1 homework part A solution
- Lesson 3.1 homework part B solution
- Lesson 3.1 homework part C solution
- Lesson 3.2 code
- Lesson 3.2 homework part A solution
- Lesson 3.2 homework part B solution
- Lesson 3.3 code
- Lesson 3.3 code - with error handling
- Lesson 3.3 homework solution
- Lesson 3.4 homework part A solution
- Lesson 3.4 homework part B solution
- Lesson 3.4 select methods code
- Lesson 3.4 SelectionManager code
- Lesson 3.5 code
- Lesson 3.5 homework solution
- Lesson 4.1 fully-define sketch code
- Lesson 4.1 sketch creation code
- Lesson 4.2a code
- Lesson 4.2a start code
- Lesson 4.2b code
- Lesson 4.2c - create plate with traversal
- Lesson 4.2c - modify features with traversal
- Lesson 4.2c code
- Lesson 4.3 find largest face code
- Lesson 4.3 selected edge length code
- Lesson 5.1 - crank
- Lesson 5.1 - drawer
- Lesson 5.1 start code
- Lesson 5.2 code
- Lesson 5.2 start code
- Lesson 5.3 - align component origins
- Lesson 5.3 - align pin origin to specific point on block
- Lesson 5.3 - align specific pt on pin to specific pt on block
- Lesson 5.3 - modify transform using ArrayData
- Lesson 5.3 - Rotate using CreateTransformRotateAxis
- Lesson 6.1 code
- Lesson 6.1 start code
- Lesson 6.2 - advanced drawings
- Lesson 6.2 - find faces
- Lesson 6.2 start code
- Lesson 6.3 code
- Lesson 7.1 code
- Lesson 7.2 - alternative to DoEvents
- Lesson 7.2 - cancel save using S_FALSE
- Lesson 7.2 - file open notification
- Lesson 7.3 - create spike
- Lesson 7.3 - create spike - start code
- Lesson 7.4 - code
- Lesson 7.4 - create spike
- Lesson 7.4 code - start
- Lesson 7.5 - Update Custom Properties With Macro Feature
- Lesson 7.5 code - Part A
- Lesson 7.5 code - Part B
- Lesson 7.5 code - Part C
- Lesson 7.5 code - Part D
- Lesson 7.5 code - Part E
- Lesson 7.5 code - Part F
- Lesson 7.5 code - Part G
- Lesson 7.5 code - Part H
- Lesson 7.5 code - Part I (spike creator)
- Rotate about axis using CreateTransformRotateAxis
- Simplified macro feature skeleton
No matching macros.
Try a broader term, another API call, or a different topic.
Need something more specific?
Talk to our developers about custom SOLIDWORKS automation.