This project generates a 3D compression spring geometry as a DXF file and creates an AutoCAD script to sweep the spring wire along the helix. It automates most of the 3D spring creation process in AutoCAD.
- Generates a helical spring path (3D polyline)
- Creates a circle profile representing the wire thickness
- Generates an AutoCAD script (.scr) to perform a sweep, creating a solid spring
| Parameter | Description |
|---|---|
| wire_diameter | Diameter of the spring wire |
| nominal_diameter | Mean diameter of the spring coil |
| turns | Number of spring turns |
| pitch | Distance between coils |
| points_per_turn | Resolution of the helix (more points → smoother spring) |
Install Autodesk Autocad ≥2025 and sign in before continuing
- Install Python (≥3.7 recommended)
- Create a virtual environment
python -m venv venv
- Activate the virtual environment
venv\Scripts\activate
- Install the requirements:
pip install -r requirements.txt
Open the Python script and adjust spring parameters if needed:
- wire_diameter = 10
- nominal_diameter = 60
- turns = 8
- pitch = 20
- points_per_turn = 80
Run the script:
python main.py
This will create two files in the same folder:
- spring.dxf -> Contains the helix path and circle profile
- spring.scr -> AutoCAD script to sweep the circle along the helix
- Open spring.dxf in AutoCAD
- Type SCRIPT in the command line
- Select spring.scr
- The script will automatically:
- Select the circle as the profile
- Select the helix as the path
- Perform a sweep, creating a 3D solid spring
If the automatic generation fails, read the command prompt for instructions
- Use 3DORBIT and REALISTIC visual style to inspect the spring
- The profile circle must be created last in the DXF so AutoCAD selects it first in the sweep
- The small Z offset avoids AutoCAD errors selecting the profile as the path
- For smoother springs, increase points_per_turn (e.g., 120–200)
- You can tweak radius and pitch to create compression, extension, or torsion springs