- About
- Features
- Tech & Concepts
- Repository structure
- How to install
- How to use
- Demo
- Next steps
- License
- Author / Contact
This project provides a SolidWorks VBA macro that reads a list of coordinates from a file and automatically creates a spline inside an active sketch.
Originally based on Xarial’s CodeStack example, and extended to include tangent angle (theta) control.
SolidWorks correctly places the points along a spline, but did not respect the desired tangency angles. While working on an aerospike nozzle contour, I needed precise control over the tangents at each point, and there were too many points to adjust manually. This macro automates the process, ensuring both position and tangency are applied correctly.
- Reads point coordinates from a text/CSV file.
- Creates a spline in the active sketch.
- Allows tangent angle control (
theta) at each point. - Can be easily modified to handle header files.
- Can be modified to work with other entities (arcs, polylines, etc).
- Language: VBA (Visual Basic for Applications).
- Platform: SolidWorks API.
- Concepts: File I/O, spline generation, tangent control, CAD automation.
solidworks-spline-macro/
├── MacroSpline.swp # compiled SolidWorks macro (runnable)
├── src/
│ └── MacroSpline.bas # source VBA code (editable text version)
├── examples/
│ └── example_points.csv # sample input file
├── assets/
│ └── banner.png
│ └── demo.gif
├── README.md
└── LICENSE
- Clone the repository
git clone git@github.com:VictorLiotti/solidworks-spline-macro.git
cd solidworks-spline-macro-
Open SolidWorks → Tools > Macro > Run
-
Select
MacroSpline.swp
(Optional) Import MacroSpline.bas if you want to inspect/modify the VBA code.
- Open or create a part file in SolidWorks.
- Open or create a sketch (must be active).
- Prepare a text file with point coordinates (e.g. x y z and theta per line)
- The macro assumes a text file with no header
- If you include a header, make sure to edit 'ReadFile()' argument in line 42:
vPts = ReadFile(FILE_PATH, True)for a file with headervPts = ReadFile(FILE_PATH, False)for a file without header
- Run the macro (Tools > Macro > Run).
- You might need to edit the macro to add your input file path in line 13:
Const FILE_PATH As String = "C:\Users\...\file.txt"
- You might need to edit the macro to add your input file path in line 13:
- A spline will be generated through the given points.
The macro expects comma-separated values (CSV style) with the following columns:
x→ X coordinatey→ Y coordinatez→ Z coordinatetheta→ tangent radial direction (angle, in radians)
Example (example_points.csv included in this repository):
x,y,z,theta
-0.008,0.006,0,0.868
-0.002,0.012,0,0.797
0.002,0.016,0,0.689
0.008,0.020,0,0.575
0.015,0.025,0,0.462
0.026,0.029,0,0.355
0.040,0.034,0,0.256
0.060,0.038,0,0.163
0.086,0.041,0,0.078
0.120,0.042,0,0.000
In this case, vPts = ReadFile(FILE_PATH, True).
Not necessarily in priority order
- Organize the VBA code and update macro package
- Add pseudocode + comments
- Add error messages for empty/invalid files.
- Improve handling for large point sets: currently, if too many points are input, the macro skips tangent control for the first points.
This project is MIT licensed.
