Learn Solidworks-api - 10 Code Examples & CST Typing Practice Test
SolidWorks API is a COM-based programming interface that allows developers to automate, customize, and extend the SolidWorks CAD software, enabling tasks from simple macros to complex design automation and integration with external systems.
Learn SOLIDWORKS-API with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
Create a New Part Document
Dim swApp As SldWorks.SldWorks
Dim swPart As ModelDoc2
Set swApp = Application.SldWorks
Set swPart = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2023\templates\Part.prtdot", 0, 0, 0)
Opens a new part document in SolidWorks via API.
Add a Sketch on Front Plane
Dim swSketchMgr As SketchManager
Set swSketchMgr = swPart.SketchManager
swPart.Extension.SelectByID2 "Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0
swSketchMgr.InsertSketch True
Creates a new sketch on the front plane.
Draw a Line in Sketch
Dim line As SketchSegment
Set line = swSketchMgr.CreateLine(0, 0, 0, 0.1, 0.1, 0)
Draws a line between two points in the active sketch.
Draw a Circle in Sketch
Dim circle As SketchSegment
Set circle = swSketchMgr.CreateCircleByRadius(0, 0, 0, 0.05)
Creates a circle at a specified center with a given radius.
Extrude a Sketch
swPart.FeatureManager.FeatureExtrusion2 True, False, False, 0, 0, 0.1, 0, False, False, False, False, 0, 0, False, False, False, False, True, False, False
Extrudes the selected sketch to create a 3D solid.
Create a Rectangle Sketch
Dim p1, p2, p3, p4 As SketchSegment
Set p1 = swSketchMgr.CreateLine(0, 0, 0, 0.1, 0, 0)
Set p2 = swSketchMgr.CreateLine(0.1, 0, 0, 0.1, 0.05, 0)
Set p3 = swSketchMgr.CreateLine(0.1, 0.05, 0, 0, 0.05, 0)
Set p4 = swSketchMgr.CreateLine(0, 0.05, 0, 0, 0, 0)
Draws a rectangle using four lines in a sketch.
Apply Fillet to Edge
swPart.Extension.SelectByID2 "Edge1", "EDGE", 0, 0, 0, False, 0, Nothing, 0
swPart.FeatureManager.InsertFeatureFillet 5, 0.01, 0, 0, 0, 0, 0, 0
Applies a fillet to a selected edge in a part.
Add Material to Part
swPart.SetMaterialPropertyName2 "Default", "Steel"
Assigns a material to the active part document.
Create a Circular Pattern
swPart.Extension.SelectByID2 "Boss-Extrude1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0
swPart.Extension.SelectByID2 "Axis1", "AXIS", 0, 0, 0, True, 0, Nothing, 0
swPart.FeatureManager.FeatureCircularPattern3 6, 360, False, True, True, True, False, 0, 0, False
Creates a circular pattern of a feature around an axis.
Save Part Document
swPart.SaveAs "C:\Users\Public\Documents\SolidWorks\part1.sldprt"
Saves the active part document to a specified path.
Frequently Asked Questions about Solidworks-api
What is Solidworks-api?
SolidWorks API is a COM-based programming interface that allows developers to automate, customize, and extend the SolidWorks CAD software, enabling tasks from simple macros to complex design automation and integration with external systems.
What are the primary use cases for Solidworks-api?
Automate repetitive modeling or drawing tasks. Create custom add-ins for design processes. Integrate SolidWorks with PLM/ERP databases. Generate reports and BOMs automatically. Custom tools for design validation and rule enforcement
What are the strengths of Solidworks-api?
Reduces repetitive manual CAD operations. Enables company-specific design rules and standards. Improves design productivity and consistency. Integrates seamlessly with existing SolidWorks environment. Supports complex workflows for large assemblies
What are the limitations of Solidworks-api?
Requires knowledge of COM and SolidWorks object model. Performance can be limited for very large assemblies. Learning curve for VBA/.NET or C# integration. Limited cross-platform support (Windows only). API changes between SolidWorks versions can affect macros/add-ins
How can I practice Solidworks-api typing speed?
CodeSpeedTest offers 10+ real Solidworks-api code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.