Skip to content

Spring Generator

KaiUR edited this page May 22, 2026 · 5 revisions

Spring Generator

File: Shape_Generation_Scripts/Spring_Generator.py
Version: 1.1
Document Type: Part


Description

Generates a parametric helical compression spring solid directly in CATIA from user-defined parameters. Settings are saved between sessions.

Open ends: A GSD helix is created as the sweep path. A circular wire cross-section sketch is placed on a plane normal to the helix at its start point and swept along the helix using a Part Design Rib to produce the solid.

Closed ends: Three helices are joined (bottom dead coil, active body, top dead coil). The solid is built entirely in GSD: a tubular surface is created with HybridShapeSweepExplicit (profile circle swept along the joined spine), flat end caps are filled with HybridShapeFill, all three surfaces are joined, and the closed surface is converted to a solid with CloseSurface. The Rib is not used for closed ends.


Requirements

Requirement Value
Python >= 3.10
pycatia >= 0.8.3
wxPython Required
Open document Part
Hybrid Design Mode Should be off (script handles this automatically)

Usage

  1. Open a CATPart document
  2. Run the script
  3. The parameter dialog appears — enter your spring parameters
  4. Click OK — a progress bar shows while the geometry is being created
  5. The spring solid is added as a new body in the part
  6. The construction geometry (helix spine, profile plane or cap surfaces) is hidden automatically after generation

Parameters

Parameter Description
Wire Diameter (mm) Diameter of the wire cross-section
Coil Diameter (mm) Mean coil diameter (centre of wire to centre of wire)
Free Length (mm) Overall uncompressed length, including dead end coils if Closed Ends is on
Active Coils Number of load-bearing coils (not including dead end coils)
Clockwise Winding direction — ticked = right-hand (clockwise from above), unticked = left-hand
Closed Ends If ticked, one dead coil (pitch = wire diameter) is added at each end — see below

Closed Ends

When Closed Ends is ticked, the spring is built from three joined helices:

Segment Pitch Height
Bottom dead coil Wire diameter (coils touching) 1 × wire diameter
Active body (Free length − 2 × wire diameter) ÷ active coils Free length − 2 × wire diameter
Top dead coil Wire diameter (coils touching) 1 × wire diameter

The three helices are joined into a single spine curve (Helix_Join). Free length includes both dead coils. The start point of each segment is calculated so that all three helices connect without gaps.

The solid is then built using the GSD surface workflow:

  1. HybridShapeSweepExplicit sweeps the bottom end cap circle along the joined spine (smooth option disabled)
  2. Two HybridShapeFill features cap the open ends — each boundary circle lies in a plane perpendicular to the spine at the respective endpoint
  3. The tube and both caps are joined into a closed surface
  4. CloseSurface converts the surface to a solid

Validation

The script validates inputs before generating:

  • All numeric fields must be greater than zero
  • Wire diameter must be less than the coil radius (Mean Coil Diameter ÷ 2)
  • Open ends: pitch (free length ÷ active coils) ≤ wire diameter → overlap warning
  • Closed ends: free length must be greater than 2 × wire diameter; main coil pitch ≤ wire diameter → overlap warning

Settings Persistence

Parameters are saved automatically to:

%APPDATA%\pycatia_scripts\Spring_Generator\user_presets.json

The next time the script runs, your last-used values are pre-filled in the dialog.


Notes

  • The spring axis is aligned with the Z-axis, with the base at the origin
  • The body is named with the key parameters: Spring | Wd:3.0mm | Cd:25.0mm | L:80.0mm | N:8.0 | CW
  • The construction geometric set (Spring_Construction) is created inside the spring body and hidden automatically after generation; it remains in the tree for editing
  • Hybrid Design Mode is temporarily disabled during generation if it is on, and restored afterwards

Home


Getting Started


Contributing


Any Document Scripts


Drawing Document Scripts


Part Document Scripts


Shape Generation Scripts


Process Document Scripts


Product Document Scripts


Utility Scripts


Legal

Clone this wiki locally