Skip to content

Plot 2D Function

KaiUR edited this page May 31, 2026 · 1 revision

Plot 2D Function

File: Shape_Generation_Scripts/Plot_2D_Function.py
Version: 1.0
Document Type: Part


Description

Evaluates a user-entered mathematical expression f(x) over a specified X range and creates the resulting curve in the active CATPart as a GSD point set and open spline. All functions from Python's math module are available in the expression (sin, cos, sqrt, log, exp, pi, e, etc.). The output plane selects which axes are used for the X and Y directions.

Settings are saved between sessions.


Requirements

Requirement Value
Python >= 3.10
pycatia >= 0.8.3
wxPython Required
Open document Part

Usage

  1. Open a CATPart document
  2. Run the script
  3. Enter the expression, X range, number of points, and output plane in the dialog
  4. Click OK — the expression is validated then a progress bar shows while geometry is created
  5. A new geometric set is added to the part containing the point set and open spline

Parameters

Parameter Description Default
f(x) = Python math expression using x as the variable sin(x) * 10
X start Start of the X range in mm 0.0
X end End of the X range in mm. Must be greater than X start. 300.0
Points Number of sample points. Minimum 2. 100
Plane Output plane: XY, XZ, or YZ XY

Expression Syntax

The expression is a Python math expression where x is the independent variable. Available functions:

Category Functions
Trigonometric sin, cos, tan, asin, acos, atan, atan2
Hyperbolic sinh, cosh, tanh
Power / log sqrt, exp, log, log2, log10
Rounding floor, ceil, fabs
Constants pi, e
Other abs, round, factorial

Examples:

Expression Curve
sin(x) * 10 Sine wave, amplitude 10 mm
x**2 / 100 Parabola
log(x + 1) * 20 Logarithm curve (x must stay > −1)
cos(x * pi / 180) * 50 Cosine where x is in degrees
sqrt(abs(x)) * 5 Square-root shape

The expression is evaluated at x = 1 during validation to catch syntax errors before touching CATIA.


Dialog Buttons

Button Action
OK Validates expression and inputs, then generates the curve
Cancel Exits without generating
Reset Defaults Restores factory default values
Clear Saved Deletes the saved user presets file
Help Opens the full in-script user manual

Output

A geometric set named f(x)_<expr> is created at the top level of the part tree containing:

f(x)_sin(x)x10
├── Points
│   ├── Pt_0001
│   ├── Pt_0002
│   │   ...
│   └── Pt_0100
└── Function_Spline  (open)

The spline is open (not closed). X and Y values are in mm.


Plane Orientation

Plane Horizontal axis Vertical axis
XY X Y (f(x))
XZ X Z (f(x))
YZ Y Z (f(x))

Settings Persistence

Settings are saved automatically to:

%APPDATA%\pycatia_scripts\Plot_2D_Function\user_presets.json

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


Notes

  • The expression must be defined and finite over the full X range — division by zero, log of a negative number, or other math errors will abort the script
  • The geo set name is a sanitised version of the expression, truncated to 30 characters
  • All point coordinates are in mm; the expression result is treated directly as mm

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