-
Notifications
You must be signed in to change notification settings - Fork 0
Common Functions
setup/templates/common_functions.py is a reference file containing helper functions that appear across multiple scripts in this repository. Copy the functions you need into your own script — do not import the file directly.
Functions are grouped into four categories:
Searches for a geometric set by name and returns it. Searches recursively through all nested sets.
def searchHybridBody(seachName, currentHybridBodies):| Parameter | Description |
|---|---|
seachName |
Name of the geometric set to find |
currentHybridBodies |
Collection to search (e.g. part.hybrid_bodies) |
Returns: The HybridBody if found, None if not found.
hb = searchHybridBody("My_Set", part.hybrid_bodies)
if hb is None:
print("Not found")Same as searchHybridBody, but also returns the /-separated path to the found set.
def searchHybridBodyWithPath(seachName, currentHybridBodies, currentPath=""):| Parameter | Description |
|---|---|
seachName |
Name of the geometric set to find |
currentHybridBodies |
Collection to search |
currentPath |
Accumulated path — leave empty on the first call |
Returns: (HybridBody, path_string) if found, (None, None) if not found.
hb, path = searchHybridBodyWithPath("My_Set", part.hybrid_bodies)
# path == "Parent_Set/Child_Set/My_Set"Replaces a hybrid shape with an isolated datum of the same type, preserving its name. Supports points (1), curves (2), lines (3), circles (4), and surfaces (5). Unsupported types are skipped with a warning.
def create_datum(hybrid_shape_factory, hybrid_shape, hybrid_body, name=None):| Parameter | Description |
|---|---|
hybrid_shape_factory |
part.hybrid_shape_factory |
hybrid_shape |
The HybridShape to isolate |
hybrid_body |
Geometric set to append the new datum to |
name |
Optional name for the datum |
Returns: None. Call part.update() after one or more create_datum calls.
create_datum(hybrid_shape_factory, my_shape, target_set, name="My_Datum")
part.update()Recursively collects all (shape_name, parent_set_name) tuples from a geometric set and all its nested children.
def collect_all_names(hybrid_body, name_list):| Parameter | Description |
|---|---|
hybrid_body |
The geometric set to scan |
name_list |
A list to append tuples to — pass an empty list on the first call |
Returns: None — appends (name, parent_set_name) tuples directly to name_list.
all_names = []
collect_all_names(target_set, all_names)
# all_names == [("Shape1", "Set_A"), ("Shape2", "Set_B"), ...]These functions require spa_workbench = part_document.spa_workbench() for coords_relative_to_axis.
Normalises a 3D vector to unit length.
def normalize_vector(vec):Returns: (x, y, z) normalised tuple, or None if the vector has zero magnitude.
Returns the dot product of two 3D vectors.
def dot_product(vec1, vec2):Returns: Scalar dot product.
Returns the cross product of two 3D vectors.
def cross_product(a, b):Returns: Cross product as a list [x, y, z].
Checks whether three 3D points are collinear (lie on the same line). Uses the cross product method with a small epsilon for floating-point tolerance.
def are_collinear(point_a, point_b, point_c):Returns: True if collinear, False otherwise.
Measures a point's coordinates relative to a given axis system.
def coords_relative_to_axis(part, spa_workbench, axis_system, point, precision=6):| Parameter | Description |
|---|---|
part |
The Part object (part_document.part) |
spa_workbench |
part_document.spa_workbench() |
axis_system |
The axis system to measure relative to |
point |
The HybridShapePointCoord to measure |
precision |
Decimal places to round to (default 6) |
Returns: (x, y, z) in the axis system's local coordinate frame.
spa_workbench = part_document.spa_workbench()
coords = coords_relative_to_axis(part, spa_workbench, my_axis, my_point)Opens a wx file-open dialog and returns the selected file path, or None if cancelled. The dialog is automatically raised above CATIA using _bring_to_front (defined as a nested function inside get_path to keep it self-contained). Imports wx and ctypes internally — no wx.App(None) call is needed before calling this function.
def get_path(wildcard):| Parameter | Description |
|---|---|
wildcard |
File type filter string, e.g. '*.txt;*.csv'
|
Returns: Selected file path as a string, or None if cancelled.
path = get_path('*.txt;*.csv')
if path is None:
exit()All functions are available in setup/templates/common_functions.py. Copy what you need — do not import the file.
Getting Started
Contributing
- Copy Name and Colour
- Export Properties To CSV
- Find And Select By Name
- Hide Planes And Axis Systems
- Rename Hybrid Shapes
- Replace Name Hybrid Shapes
- Reset Visual Properties
- Screenshot White Background
- Swap Names
- Toggle Show Hide Geometric Set
- Add Border And Title Block
- Add Border And Title Block With Values
- Batch CATDrawing To DXF
- Batch CATDrawing To PDF
- Create Drawing Border And Title Block
- Create Drawing Border And Title Block With Values
- Export Drawing Dimensions To CSV
- Update All Drawing Views
- Update Title Block From Properties
- Update Title Block Headings
- Axis To Axis Keep History
- Axis To Axis Keep History And Structure
- Axis To Axis Keep Name
- Axis To Axis Keep Name And Structure
- Batch Isolate Geometric Set
- Check Duplicate Names In Geometric Set
- Check Open Bodies
- Colour Code By Geometric Set
- Copy Geometric Set To New Part
- Copy Parameters Between Parts
- Create Construction Planes
- Create Spline From Coordinates
- Create ISM OSM STEP Files
- Delete Deactivated Features
- Export 3D Annotations To CSV
- Export All Parameters To CSV
- Export Curve Lengths Surface Areas To CSV
- Export Geometric Set Structure To CSV
- Export Holes To CSV
- Export Mass CoG Inertia To CSV
- Export Parameter Dependencies To CSV
- Export Points Axis and Geo Set To CSV
- Export Points Axis and Geo Set To XYZ
- Export Points Geo Set To CSV
- Export Points Geo Set To XYZ
- Export Sketch Constraints To CSV
- Extract Boundary Curves
- IGES Export Curve Axis
- Insert Points Catia
- Insert Points Catia Keep History
- Insert Points Catia With Names
- Insert Points Catia With Names Keep History
- Join Explicit No Connect
- Join Explicit No Connect Curve
- Join Explicit No Connect Surface
- List Properties To CSV
- Match Properties In Geometric Set
- Measure Curve With 3 Points As Circle
- Measure Curve With 3 Points As Circle Keep Con
- Measure Radius Surface
- Measure Radius Surface Keep Con
- Measure Radius Surface Keep Con Auto Edge
- Mirror Keep History
- Mirror Keep History And Structure
- Mirror Keep Name
- Mirror Keep Name And Structure
- Publish Hybrid Shapes In Geometric Set
- Reorder Geometric Set Alphabetically
- Rotate Angle Keep History
- Rotate Angle Keep History And Structure
- Rotate Angle Keep Name
- Rotate Angle Keep Name And Structure
- Rotate Three Points Keep History
- Rotate Three Points Keep History And Structure
- Rotate Three Points Keep Name
- Rotate Three Points Keep Name And Structure
- Scale Keep History
- Scale Keep History And Structure
- Scale Keep Name
- Scale Keep Name And Structure
- Select By Colour
- Spline Through Points In Geometric Set
- Translate Direction Distance Keep History
- Translate Direction Distance Keep History And Structure
- Translate Direction Distance Keep Name
- Translate Direction Distance Keep Name And Structure
- Custom Coordinate Airfoil Generator
- Ellipse Generator
- Hole Size Test Plate Generator
- Involute Gear Generator
- NACA 4 Digit Airfoil Generator
- NACA 5 Digit Airfoil Generator
- Plot 2D Function
- Plot 3D Parametric Curve
- Regular Polygon Generator
- Sine Wave Curve Generator
- Spring Generator
- Check Operation Parameters Against Limits
- Export NC Program Names To CSV
- Export Process Table Parameters
- Export Resource List
- Export Tool List From Process
- Rename Operations From Tool Name
- Batch Instance Name Equal Part Number
- Batch Rename Instances
- BOM Export To CSV
- BOM Export With Materials
- Check Missing Files
- Clash Detection Export
- Export Assembly As STEP
- Export Component Positions To CSV
- Save Child Parts To STEP
- Save Child Parts To STL
- Backup CATIA Settings
- Clear Script Settings
- Clear CATIA Temp Files
- Configure CATIA Version Settings
- Kill CATIA Processes
- Open CATIA Settings Folder
- Reset CATIA Settings
- Restore CATIA Settings
- Set CATIA Environment Variable
- Toggle CATIA No Start Document
Legal