AI generated shapes
Parametric parts in IGEMS CAD/CAM are written in Python, which is a very well documented and used programming language. We’ve generated a Custom GPT (linked below) with our knowledge and samples about parametric parts. All you need to do is ask the GPT for a part.
“Create an L-shaped bracket with one hole in each end and fillets on all outside corners.”
Custom parametric shape ChatGPT
Paste the generated code as follows:
- Open Parametric shapes in IGEMS CAD/CAM
- Select a folder in the left menu.
- Click the grid icon in the bottom right corner.
- Click New Script.
- Paste your part code from the Custom GPT and save the file.
- To edit the script, double click on the part and click "Edit script". (Reason with ChatGPT to get the shape you want).
Introduction
Parametric Shapes in IGEMS are Python-based geometric definitions that allow you to create dimension-driven parts. Unlike static geometry, parametric shapes can be easily modified by changing their parameters, making them ideal for creating families of similar parts or quickly adapting designs to new specifications.
Each parametric shape is defined by a Python script (.py file) that specifies:
- Parameters that can be adjusted by the user
- The geometry generation logic
- Dimensions for visualization and documentation
Using Parametric Shapes
To insert a parametric shape into your CAD drawing:
- Access the Parametric Shapes command from the IGEMS CAD/Shapes toolbar
- The Shape Selection Dialog will appear, showing available shapes organized by category
- Browse through folders to find the desired shape
- Select a shape from the thumbnail view
- Double-click the shape to open the Parameter Dialog
- Adjust parameters as needed and preview the result
- Click OK to insert the shape into your drawing
The Shape Selection Dialog
The Shape Selection Dialog is your gateway to the parametric shapes library. It provides an organized view of all available shapes with visual thumbnails for easy identification.
Dialog Components
Folder List (Left Panel)
The left panel displays shape categories organized in folders:
- Standard: Built-in shapes provided with IGEMS
- Custom Folders: User-created organizational folders
- User: Custom shapes in the shared directory
Thumbnail View (Right Panel)
The right panel displays visual previews of all shapes in the selected folder. Each thumbnail shows a rendered preview of the shape, making it easy to identify the part you need.
Tip: Thumbnails are automatically generated and cached. They update when you modify a script, ensuring you always see the current version.
Menu Button (Hamburger Icon)
The menu button in the top-right corner provides additional options:
- Edit script: Opens the selected script in your default text editor
- New script: Creates a new parametric shape script
- New folder: Creates a new category folder
- Open folder: Opens the current folder in Windows Explorer
- Regenerate thumbnails: Forces regeneration of all thumbnail images
Keyboard Shortcuts
- Double-click: Opens the Parameter Dialog for the selected shape
- Ctrl + Double-click: Opens the script file in your text editor
- Ctrl + Shift + R: Regenerates all thumbnails in the current folder
The Parameter Dialog
After selecting a shape, the Parameter Dialog allows you to customize the part by adjusting its parameters. This dialog provides real-time preview and intelligent unit handling.
Dialog Components
Parameter Panel (Left Side)
The parameter panel displays all adjustable parameters defined in the script. Each parameter is presented with an appropriate control:
| Parameter Type | Control Type | Description |
|---|---|---|
| Linear | Numeric input with units | Dimensions in mm or inches based on system settings |
| Angular | Numeric input (degrees) | Angles in degrees, counter-clockwise |
| Integer | Numeric input | Whole numbers without decimals |
| Real | Numeric input | Unitless floating-point numbers |
| Boolean | Checkbox | True/False toggle option |
Preview Panel (Right Side)
The preview panel shows a visual representation of the part with the default parameter values. The preview includes:
- The shape
- Dimension lines and annotations
Interactive Preview: Click and hold on the preview panel to see the shape with the actual parameters you have input. Release to return to the clean view.
Control Buttons
- OK: Applies the parameters and inserts the part into your drawing
- Cancel: Closes the dialog without inserting the part
- Default: Restores all parameters to their default values
- Reload: Reloads the script from disk (useful when editing the script externally)
- Edit: Opens the script file in your default text editor
Unit System Handling
The parameter dialog automatically adapts to your IGEMS unit settings:
- Metric Mode: Linear parameters display in millimeters
- Imperial Mode: Linear parameters display in inches
When defining scripts, you provide default values for both unit systems, ensuring the part scales appropriately regardless of the user's unit preference.
Creating Your Own Scripts
Creating custom parametric shapes is straightforward. You can start from scratch or use an existing script as a template.
Creating a New Script
- Open the Shape Selection Dialog
- Select the folder where you want to create the script
- Click the menu button (hamburger icon) and select "New script"
- Enter a name for your script
- The system creates a template script and opens it in your text editor
Tip: Script files are stored as
.pyfiles in the IGEMS parts directory. You can also create them manually using any text editor.
Script File Locations
| Directory | Purpose | Typical Location |
|---|---|---|
| Standard | Built-in IGEMS shapes | DATA/PythonShapes |
| User | User-created shapes | SHARED/PythonShapes |
| Custom Folders | Organized categories | Subfolders under Standard or Shared |
Editing Existing Scripts
You can edit any script by:
- Right-clicking it in the Shape Selection Dialog and choosing "Edit script"
- Using Ctrl + Double-click on the shape thumbnail
- Clicking "Edit" in the Parameter Dialog (Recommended)
- Opening the
.pyfile directly in a text editor
Warning: When editing built-in shapes in the Standard folder, consider making a copy to the User folder first to preserve the original. If you edit standard shapes they might be overwritten if you update IGEMS!
Script Structure
Every parametric shape script follows a consistent structure with two main sections: parameter definitions and the geometry generation function.
Basic Template
# Parameter definitions (global scope)
linpar("A", 200, 8) # Linear parameter: 200mm default, 8" default
linpar("B", 150, 6) # Another linear parameter
angpar("Angle", 45) # Angular parameter: 45 degrees default
# Geometry generation function
def generate():
# Draw the geometry
rect(0, 0, A, B)
# Add dimensions
dimlin("A", 0, 0, A, 0, False)
dimlin("B", 0, 0, 0, B, True)
Script Components
1. Import Statements (Optional)
If you need mathematical functions, import the Python math module:
from math import *
2. Parameter Definitions
Parameters must be defined at the global scope (outside any function). They define what the user can adjust in the Parameter Dialog:
linpar("Width", 100, 4) # Linear: metric default, imperial default
angpar("CornerAngle", 90) # Angular: degrees
intpar("Holes", 4) # Integer: whole number
realpar("Ratio", 1.5) # Real: unitless number
boolpar("Mirror", False) # Boolean: True/False
3. The generate() Function
The generate() function is where you define the shape geometry. This function is called automatically when the part needs to be drawn:
def generate():
# Your geometry code here
moveto(0, 0)
lineto(Width, 0)
lineto(Width, Height)
close()
Important: Parameters defined globally (like Width, Height) are automatically available as variables inside the
generate()function.
Coordinate System
The geometry uses a standard Cartesian coordinate system:
- Origin (0, 0) is at the lower-left
- X-axis extends to the right (positive direction)
- Y-axis extends upward (positive direction)
- Angles are measured counter-clockwise from the positive X-axis
- Angular units are in degrees
Parameter API Reference
Parameters define the adjustable inputs for your parametric shape. They must be declared at the global scope.
linpar() - Linear Parameter
void linpar(string varid, double mm_default, double in_default)
Defines a linear dimension parameter with separate defaults for metric and imperial modes.
| Parameter | Type | Description |
|---|---|---|
| varid | string | Variable identifier used in the script and displayed to the user |
| mm_default | double | Default value in millimeters (metric mode) |
| in_default | double | Default value in inches (imperial mode) |
Example:
linpar("Width", 200, 8) # 200mm or 8" depending on unit system
linpar("Height", 150, 6) # 150mm or 6"
linpar("Radius", 25, 1) # 25mm or 1"
angpar() - Angular Parameter
void angpar(string varid, double defaultValue)
Defines an angular parameter in degrees.
| Parameter | Type | Description |
|---|---|---|
| varid | string | Variable identifier |
| defaultValue | double | Default angle in degrees (counter-clockwise) |
Example:
angpar("Rotation", 45) # 45 degree rotation
angpar("ArcSpan", 90) # 90 degree arc
angpar("Skew", 15) # 15 degree skew angle
intpar() - Integer Parameter
void intpar(string varid, int defaultValue)
Defines an integer parameter (whole numbers only).
| Parameter | Type | Description |
|---|---|---|
| varid | string | Variable identifier |
| defaultValue | int | Default integer value |
Example:
intpar("HoleCount", 4) # Number of holes
intpar("Teeth", 24) # Number of gear teeth
intpar("Sides", 6) # Number of polygon sides
realpar() - Real Number Parameter
void realpar(string varid, double defaultValue)
Defines a unitless floating-point parameter.
| Parameter | Type | Description |
|---|---|---|
| varid | string | Variable identifier |
| defaultValue | double | Default floating-point value |
Example:
realpar("Ratio", 1.618) # Golden ratio
realpar("Scale", 1.5) # Scale factor
realpar("Factor", 0.75) # Multiplication factor
boolpar() - Boolean Parameter
void boolpar(string varid, bool defaultValue)
Defines a boolean (True/False) parameter displayed as a checkbox.
| Parameter | Type | Description |
|---|---|---|
| varid | string | Variable identifier |
| defaultValue | bool | Default state (True or False) |
Example:
boolpar("Mirror", False) # Mirror the shape
boolpar("Rounded", True) # Use rounded corners
boolpar("ShowCenter", False) # Display center mark
Usage Tip: In the
generate()function, boolean parameters evaluate to 1.0 (True) or 0.0 (False), so you can use them in conditional statements:if Mirror: ...
Geometry API Reference
Geometry functions are used inside the generate() function to create the shape. The system maintains a "pen" position that moves as you draw.
moveto() - Move Pen
void moveto(double x, double y)
Moves the pen to a new position without drawing anything. Use this to start a new contour or jump to a different location.
Example:
moveto(10, 20) # Move pen to coordinates (10, 20) moveto(0, 0) # Move to origin
lineto() - Draw Line
void lineto(double x, double y)
Draws a straight line from the current pen position to the specified point and moves the pen there.
Example:
moveto(0, 0) # Start at origin lineto(100, 0) # Draw horizontal line lineto(100, 50) # Draw vertical line lineto(0, 50) # Draw another horizontal line close() # Close the rectangle
arcto() - Draw Arc
void arcto(double x, double y, double cenx, double ceny, bool ccw)
Draws a circular arc from the current pen position to the specified endpoint, using the specified center point.
| Parameter | Type | Description |
|---|---|---|
| x, y | double | Endpoint coordinates of the arc |
| cenx, ceny | double | Center point of the arc |
| ccw | bool | True for counter-clockwise, False for clockwise |
Example:
moveto(0, 0) lineto(100, 0) arcto(100, 50, 100, 25, False) # Clockwise arc with center at (100, 25) lineto(0, 50) arcto(0, 0, 0, 25, True) # Counter-clockwise arc
arctob() – Draw Arc with Bulge
arctob(x, y, bulge)
Draws an arc from the current pen position to the specified endpoint using a bulge factor. The bulge is the tangent of 1/4 of the included angle. Positive bulge creates a counter-clockwise arc; negative creates clockwise.
| Parameter | Type | Description |
|---|---|---|
| x | double | X coordinate of the arc endpoint |
| y | double | Y coordinate of the arc endpoint |
| bulge | double | Bulge factor (tan(angle/4)). Range: -1 to 1 for arcs ≤180°. 0 = straight line, 1 = semicircle CCW, -1 = semicircle CW |
Example:
moveto(0, 0)
arctob(100, 0, 0.5) # Arc with bulge 0.5 (approx 106°)
arctob(100, 100, -1) # Semicircle clockwiseNote: Bulge values: 0 = straight line, ±0.414 ≈ 90° arc, ±1 = 180° semicircle. Use math.tan(angle/4) to calculate exact bulge for a desired angle.
close() - Close Contour
void close()
Closes the current contour by adding a line segment from the current position back to the starting position (if needed).
Example:
moveto(0, 0) lineto(100, 0) lineto(100, 100) lineto(0, 100) close() # Closes back to (0, 0)
Note: You can create multiple closed contours in a single script by using
moveto()to start each new contour.
circle() - Draw Circle
void circle(double x, double y, double r)
Creates a complete circle as a separate contour.
| Parameter | Type | Description |
|---|---|---|
| x, y | double | Center point coordinates |
| r | double | Radius of the circle |
Example:
circle(50, 50, 25) # Circle at (50, 50) with radius 25 circle(0, 0, D/2) # Circle at origin with radius = D/2
Warning: Do not call
circle()while in the middle of creating a moveto/lineto contour. Complete and close your contour first, or callcircle()before starting the contour.
rect() - Draw Rectangle
void rect(double x0, double y0, double x1, double y1, double r=0.0)
Creates a rectangle as a separate contour, with optional rounded corners.
| Parameter | Type | Description |
|---|---|---|
| x0, y0 | double | First corner coordinates |
| x1, y1 | double | Opposite corner coordinates |
| r | double | Corner radius for rounded corners (optional, default = 0) |
Example:
rect(0, 0, 100, 50) # Simple rectangle rect(0, 0, A, B) # Rectangle using parameters rect(10, 10, 90, 40, 5) # Rectangle with 5mm corner radius
Warning: Like
circle(), do not callrect()while in the middle of a moveto/lineto contour.
Dimension API Reference
Dimensions are annotations that appear in the preview and help users understand the part's measurements. They are only visible in edit/preview mode, not in the final geometry.
dimlin() - Linear Dimension
void dimlin(string txt, double x0, double y0, double x1, double y1, bool leftSide=true, double witnessPixels=32)
Creates a linear dimension between two points.
| Parameter | Type | Description |
|---|---|---|
| txt | string | Dimension text (typically the parameter name) |
| x0, y0 | double | First point coordinates |
| x1, y1 | double | Second point coordinates |
| leftSide | bool | True to place dimension on left/top, False for right/bottom |
| witnessPixels | double | Distance of dimension line from the geometry in screen pixels |
Example:
dimlin("A", 0, 0, 100, 0, False) # Horizontal dimension below
dimlin("B", 0, 0, 0, 50, True) # Vertical dimension on left
dimlin("C", 10, 10, 90, 10, False, 50) # Custom witness line distance
[INSERT IMAGE: Diagram showing linear dimensions with leftSide = True and False, with labeled witness lines]
dimrad() - Radius Dimension
void dimrad(string txt, double xc, double yc, double r, double ang, double witnessPixels=32)
Creates a radius dimension for circular features.
| Parameter | Type | Description |
|---|---|---|
| txt | string | Dimension text (typically "R" followed by parameter name) |
| xc, yc | double | Center point of the circle/arc |
| r | double | Radius value |
| ang | double | Angle in degrees for dimension placement |
| witnessPixels | double | Extension distance in screen pixels |
Example:
circle(50, 50, 20)
dimrad("R", 50, 50, 20, 45) # Radius dimension at 45 degrees
circle(0, 0, C/2)
dimrad("C", 0, 0, C/2, 225) # Radius dimension at 225 degrees
dimdia() - Diameter Dimension
void dimdia(string txt, double xc, double yc, double dia, double ang, double witnessPixels=32)
Creates a diameter dimension for circular features.
| Parameter | Type | Description |
|---|---|---|
| txt | string | Dimension text (typically "Ø" or "D" followed by parameter name) |
| xc, yc | double | Center point of the circle |
| dia | double | Diameter value |
| ang | double | Angle in degrees for dimension placement |
| witnessPixels | double | Extension distance in screen pixels |
Example:
circle(0, 0, D/2)
dimdia("D", 0, 0, D, 45) # Diameter dimension at 45 degrees
[INSERT IMAGE: Side-by-side comparison showing radius vs diameter dimensions]
dimtxt() - Text Annotation
void dimtxt(string txt, double x, double y)
Creates a text annotation at a specific location (not a measurement dimension).
| Parameter | Type | Description |
|---|---|---|
| txt | string | Text to display |
| x, y | double | Position coordinates for the text |
Example:
dimtxt("Center", 0, 0) # Label center point
dimtxt("1", x1, y1) # Number a feature
dimtxt("Hole " + str(i+1), x, y) # Dynamic text in a loop
dimarc() – Arc Length Dimension
dimarc(txt, x1, y1, x2, y2, cx, cy, ccw)
Creates an arc length dimension showing the curved distance along an arc. The dimension follows the arc path from start to end point.
| Parameter | Type | Description |
|---|---|---|
| txt | string | Dimension text |
| x1 | double | X coordinate of the arc start point |
| y1 | double | Y coordinate of the arc start point |
| x2 | double | X coordinate of the arc end point |
| y2 | double | Y coordinate of the arc end point |
| cx | double | X coordinate of the arc center |
| cy | double | Y coordinate of the arc center |
| ccw | bool | True for counter-clockwise arc, False for clockwise |
Example:
# Dimension an arc from (0,50) to (50,0) centered at (0,0)
dimarc("Arc", 0, 50, 50, 0, 0, 0, False) # CW arcText Functions
text() – Add Text Entity
text(txt, x, y, height=12, angle=0, xjust=2, yjust=0)
Adds a text entity to the shape output. Unlike dimension text (dimtxt), this text becomes part of the actual geometry output and can be included in the final drawing.
| Parameter | Type | Description |
|---|---|---|
| txt | string | Text content to display |
| x | double | X coordinate of the text position |
| y | double | Y coordinate of the text position |
| height | double | Text height in current units (default: 12) |
| angle | double | Rotation angle in degrees, counter-clockwise (default: 0) |
| xjust | int | Horizontal justification: 0=Left, 1=Right, 2=Center (default: 2) |
| yjust | int | Vertical justification: 0=Baseline, 1=Top 2=Center (default: 0) |
Example:
text("Part #123", 50, 100, 10) # 10mm high text
text("FRONT", 0, 0, 8, 90) # Rotated 90°
text("Centered", 50, 50, 12, 0, 1, 2) # Center justifiedNote: Text uses the ISOCP font by default. The xjust and yjust parameters correspond to TextJustify enumeration values in IGEMS.
Utility Functions
Utility functions help with geometric calculations and debugging.
polar() - Polar Coordinates
(double, double) polar(double x, double y, double angle, double distance)
Returns a new point at a specified angle and distance from a given point. This is extremely useful for calculating positions in circular patterns or angular offsets.
| Parameter | Type | Description |
|---|---|---|
| x, y | double | Starting point coordinates |
| angle | double | Angle in radians (use math.pi for conversions) |
| distance | double | Distance from the starting point |
Returns: A tuple (x, y) representing the new point coordinates.
Example:
from math import *
# Place 4 holes in a circular pattern
for i in range(4):
angle_rad = pi * (90 + 90*i) / 180
x, y = polar(50, 50, angle_rad, 30)
circle(x, y, 5)
# Calculate point at angle from center
px, py = polar(0, 0, pi/4, 100) # 45 degrees, 100mm away
angle() - Calculate Angle Between Points
double angle(double x0, double y0, double x1, double y1)
Returns the Cartesian angle in radians from one point to another.
| Parameter | Type | Description |
|---|---|---|
| x0, y0 | double | Starting point coordinates |
| x1, y1 | double | Ending point coordinates |
Returns: Angle in radians (counter-clockwise from positive X-axis)
Example:
from math import * # Calculate angle between two points a = angle(0, 0, 100, 100) # Returns pi/4 (45 degrees) # Use in arc generation x1, y1 = 10, 20 x2, y2 = 50, 60 ang = angle(x1, y1, x2, y2) # Use this angle for positioning elements
distance() – Calculate Distance Between Points
distance(x1, y1, x2, y2) → double
Calculates the Euclidean distance between two points.
| Parameter | Type | Description |
|---|---|---|
| x1 | double | X coordinate of the first point |
| y1 | double | Y coordinate of the first point |
| x2 | double | X coordinate of the second point |
| y2 | double | Y coordinate of the second point |
Returns: Distance between the two points in current units.
Example:
# Calculate distance between two points
d = distance(0, 0, 100, 100) # Returns ~141.42 (100√2)
# Check if a point is within range
if distance(px, py, cx, cy) < max_radius:
circle(px, py, hole_radius)alert() - Debug Message
void alert(string msg)
Displays a message box with the specified text. Use this for debugging your scripts.
Example:
alert("Debug: A = " + str(A))
alert("Calculating arc at position " + str(x) + ", " + str(y))
Warning: Remove or comment out
alert()calls before distributing your script, as they will interrupt the user experience.
Advanced Functions
Advanced functions provide specialized capabilities for complex geometry manipulation.
arcfit() – Fit Arcs to Polyline
arcfit(cntrindex, tol)
Applies arc fitting to a polyline contour, converting sequences of line segments into smooth arcs where possible. This is useful when you've generated a shape from many small line segments (e.g., from mathematical functions) and want to simplify it with arcs.
| Parameter | Type | Description |
|---|---|---|
| cntrindex | int | Index of the contour to process (returned by moveto()) |
| tol | double | Tolerance for arc fitting. Minimum 0.00001. Smaller values preserve more detail |
Example:
from math import sin, cos, pi
# Create a curve from many line segments
idx = moveto(0, 0)
for i in range(100):
t = i * pi / 50
lineto(t * 10, sin(t) * 50)
# Fit arcs to simplify the geometry
arcfit(idx, 0.1) # 0.1mm toleranceNote: The contour index is returned by moveto(). Store this value when starting a contour if you plan to use arcfit() on it later.
polygeom() – Add Polygon Geometry
polygeom(geom)
Adds pre-existing polygon or region geometry to the shape output. This function accepts Poly2d or Region2d objects and incorporates them into the current shape.
| Parameter | Type | Description |
|---|---|---|
| geom | object | A Poly2d or Region2d geometry object. Pass None/null to skip |
Usage:
This function is primarily for advanced use cases where you need to incorporate geometry generated by other IGEMS functions or external calculations. The geometry object must be a valid Poly2d or Region2d instance.
Warning: If an unsupported geometry type is passed, an exception is thrown. Always ensure you're passing valid Poly2d or Region2d objects.
Complete Examples
Example 1: Simple Circle
The simplest parametric shape - a circle with adjustable diameter.
linpar("D", 200, 8)
def generate():
circle(0, 0, D/2)
dimdia("D", 0, 0, D, 45)
Example 2: Rectangle with Parameters
A basic rectangle with independent width and height parameters.
linpar("A", 200, 8)
linpar("B", 100, 6)
def generate():
rect(0, 0, A, B)
dimlin("A", 0, 0, A, 0, False)
dimlin("B", 0, 0, 0, B, True)
Example 3: Rounded Rectangle
A more complex shape with rounded corners and chamfers.
linpar("A", 200, 8)
linpar("B", 150, 6)
linpar("C", 60, 2.5)
linpar("D", 70, 3)
linpar("E", 40, 1.5)
linpar("F", 50, 2)
def generate():
cx = A - C + E
cy = B - D + E
moveto(A, 0)
lineto(A, B - D)
lineto(cx, cy - E)
arcto(cx - E, cy, cx, cy, False)
lineto(A - C, B)
lineto(0, B)
lineto(0, F)
arcto(F, 0, 0, 0, False)
close()
dimlin("A", 0, 0, A, 0, False)
dimlin("B", 0, 0, 0, B, True)
dimlin("C", A - C, B, A, B, True)
dimlin("D", A, B - D, A, B, False)
dimrad("E", cx, cy, E, 225)
dimrad("F", 0, 0, F, 45)
Example 4: Concentric Circles
Multiple circles with different diameters.
linpar("A", 200, 8)
linpar("B", 100, 4)
def generate():
circle(0, 0, A / 2)
circle(0, 0, B / 2)
dimdia("A", 0, 0, A, 45)
dimdia("B", 0, 0, B, 180)
Example 5: Circular Hole Pattern
Using loops and mathematical functions to create a bolt circle pattern.
from math import *
linpar("A", 200, 9) # Overall diameter
linpar("B", 150, 7) # Bolt circle diameter
linpar("C", 30, 1) # Hole diameter
linpar("D", 100, 4) # Center hole diameter
intpar("N", 8) # Number of holes
def generate():
angle = 360.0 / N
# Create holes in circular pattern
for i in range(N):
angle_deg = 90 + angle * i
angle_rad = pi * angle_deg / 180
x = round(A/2 + B/2 * cos(angle_rad), 3)
y = round(A/2 + B/2 * sin(angle_rad), 3)
circle(x, y, C/2)
# Number the holes
strcrc = str(i+1)
if i == N-1:
strcrc = "N"
dimtxt(strcrc, x, y)
# Center hole and outer circle
circle(A/2, A/2, D/2)
circle(A/2, A/2, A/2)
# Dimensions
dimlin("A", 0, A/2, A, A/2, False, 350)
dimlin("B", (A-B)/2, A/2, A-(A-B)/2, A/2, False, 310)
dimlin("D", (A-D)/2, A/2, A-(A-D)/2, A/2, False, 270)
dimlin("C", A/2-C/2, (A-B)/2, A/2+C/2, (A-B)/2, False, 80)
Example 6: Gothic Arch Shape
A decorative shape using polar coordinates and arcs.
from math import *
linpar("A", 200, 8)
linpar("B", 100, 4)
linpar("C", 20, 1)
def angle(x1, y1, x2, y2):
dx = x2 - x1
dy = y2 - y1
angle_rad = atan2(dy, dx)
return angle_rad
def generate():
x1, y1 = C, C
x2, y2 = C + A, C
x3, y3 = C + A/2, C + B
moveto(C, 0)
lineto(C + A, 0)
p1, p2 = polar(x2, y2, angle(x2, y2, x3, y3) - pi/2, C)
arcto(p1, p2, C + A, C, True)
p1, p2 = polar(x3, y3, angle(x2, y2, x3, y3) - pi/2, C)
lineto(p1, p2)
p1, p2 = polar(x3, y3, angle(x3, y3, x1, y1) - pi/2, C)
arcto(p1, p2, C + A/2, C + B, True)
p1, p2 = polar(x1, y1, angle(x3, y3, x1, y1) - pi/2, C)
lineto(p1, p2)
arcto(C, 0, C, C, True)
close()
dimlin("A", C, C, A + C, C, False, 80)
dimlin("B", C + A/2, C, C + A/2, B + C, True, 280)
dimrad("C", C, C, C, 230)
Best Practices and Tips
Naming Conventions
- Parameter IDs: Use single uppercase letters (A, B, C) for primary dimensions, or descriptive names (Width, Height, Radius)
- File Names: Use descriptive names with numbers for organization (001_rectangle.py, 045_circles.py)
- Dimension Text: Match parameter names for clarity
Script Organization
# 1. Imports at top
from math import *
# 2. Parameter definitions
linpar("A", 200, 8)
linpar("B", 100, 4)
# 3. Helper functions (if needed)
def calculate_offset(x, y, angle, dist):
return x + dist * cos(angle), y + dist * sin(angle)
# 4. Generate function
def generate():
# Geometry code here
rect(0, 0, A, B)
# Dimensions at end
dimlin("A", 0, 0, A, 0, False)
dimlin("B", 0, 0, 0, B, True)
Dimension Placement Tips
- Place dimensions outside the part outline for clarity
- Use consistent witness line distances (32 or 50 pixels work well)
- For multiple dimensions on the same side, increase witness line distance for outer dimensions (50, 80, 110, etc.)
- Place radius/diameter dimensions at 45-degree increments (45, 135, 225, 315) for consistency
Common Pitfalls to Avoid
1. Mixing contour types
Don't call circle() or rect() in the middle of a moveto/lineto sequence.
# Wrong: moveto(0, 0) lineto(50, 0) circle(25, 25, 10) # This breaks the contour! lineto(50, 50) # Right: circle(25, 25, 10) # Draw circle first moveto(0, 0) # Then start contour lineto(50, 0) lineto(50, 50)
2. Forgetting to close contours
Always call close() to complete a shape.
# Wrong: moveto(0, 0) lineto(100, 0) lineto(100, 100) lineto(0, 100) # Missing close() - contour won't be complete! # Right: moveto(0, 0) lineto(100, 0) lineto(100, 100) lineto(0, 100) close() # Properly closed
3. Using degrees instead of radians
Python's math functions use radians, not degrees.
# Wrong: from math import * x, y = polar(0, 0, 45, 100) # This is 45 radians, not degrees! # Right: from math import * x, y = polar(0, 0, pi/4, 100) # 45 degrees in radians # Or: x, y = polar(0, 0, 45 * pi/180, 100)
Testing Your Scripts
- Start simple: Begin with basic shapes and add complexity gradually
- Test with extreme values: Try very small and very large parameter values
- Test both unit systems: Check that metric and imperial defaults make sense
- Verify dimensions: Ensure all dimensions match the actual geometry
- Check for errors: Look for Python errors in the IGEMS error log
Performance Optimization
- Avoid excessive calculations in loops - precompute values when possible
- Use
round()to limit decimal places:x = round(value, 3) - For complex shapes with many points, consider simplifying the geometry
- Remove debug
alert()calls from production scripts
Advanced Techniques
Conditional Geometry
Use boolean parameters to create variants:
boolpar("Rounded", True)
linpar("A", 100, 4)
linpar("R", 10, 0.4)
def generate():
if Rounded:
rect(0, 0, A, A, R) # Rounded corners
else:
rect(0, 0, A, A) # Square corners
dimlin("A", 0, 0, A, 0, False)
if Rounded:
dimrad("R", 0, 0, R, 45)
Array Patterns
Create repeated features:
from math import *
linpar("Spacing", 50, 2)
intpar("Count", 5)
linpar("HoleSize", 10, 0.4)
def generate():
for i in range(Count):
x = i * Spacing
circle(x, 0, HoleSize/2)
dimtxt(str(i+1), x, -15)
if Count > 1:
dimlin("Spacing", 0, 0, Spacing, 0, False)
Calculated Parameters
Derive values from input parameters:
linpar("OuterDia", 100, 4)
realpar("WallThickness", 10, 0.4)
def generate():
inner_dia = OuterDia - 2 * WallThickness
circle(0, 0, OuterDia/2)
circle(0, 0, inner_dia/2)
dimdia("D1", 0, 0, OuterDia, 45)
dimdia("D2", 0, 0, inner_dia, 180)
Debugging Tips
- Use
alert()to display variable values during development - Start with a working example and modify incrementally
- Comment out sections to isolate problems
- Check the IGEMS log file for Python error messages
- Use the "Reload" button in the Parameter Dialog when editing scripts
Documentation and Sharing
- Add comments to your scripts to explain complex calculations
- Include a header comment with the script purpose and author
- Organize scripts into logical folders
- Use descriptive parameter names that are self-explanatory
- Test thoroughly before sharing with other users
Pro Tip: Create a template script with your standard header and commonly used helper functions. Copy this template when starting new scripts for consistency.
Getting Help
If you encounter issues or have questions:
- Review the example scripts in the Standard folder
- Check this knowledge base article for API reference
- Examine error messages in the IGEMS log
- Contact IGEMS technical support with your script file and error description
Additional Resources: The Standard folder contains many example scripts that demonstrate various techniques. These are excellent learning resources and can serve as templates for your own scripts.
Last Updated: 2025 | IGEMS CAD/CAM Software