-
Notifications
You must be signed in to change notification settings - Fork 0
Script Templates
Ready-to-use starting points for writing new scripts. Templates live in setup/templates/ in the repository — copy the one that matches your use case, rename it with Snake_Case_Descriptive_Name.py, and work through the EDIT: and # TODO: markers.
| Template | Document | GUI dialog | Saves settings | Progress bar |
|---|---|---|---|---|
any_document_basic.py |
Any | No | No | No |
any_document_dialog.py |
Any | Yes | No | No |
part_document_basic.py |
CATPart | No | No | No |
part_document_dialog.py |
CATPart | Yes | No | No |
part_document_dialog_persistence.py |
CATPart | Yes | Yes | No |
part_document_dialog_persistence_progress.py |
CATPart | Yes | Yes | Yes |
process_document_basic.py |
CATProcess | No | No | No |
process_document_dialog.py |
CATProcess | Yes | No | No |
process_document_dialog_persistence.py |
CATProcess | Yes | Yes | No |
product_document_basic.py |
CATProduct | No | No | No |
When to use each variant:
- Basic — script runs silently with no user input (e.g. hide all planes, batch export)
- Dialog — script needs one-time inputs from the user that do not need to be remembered
- Dialog + Persistence — script has configurable settings the user will reuse across sessions (e.g. limit values, output paths, toggle options)
- Dialog + Persistence + Progress — same as above, but the operation is slow enough to warrant a progress bar (geometry generation, large batch operations)
Every template follows the same structure:
'''
-----------------------------------------------------------------------------------------------------------------------
Script name: Your_Script_Name.py
...
-----------------------------------------------------------------------------------------------------------------------
'''Fill in every field. CatiaMenuWin32 reads Purpose for the button subtitle and Description for the Script Details panel. See Writing Scripts for full header rules.
Standard block at the top. Only add what the script actually uses.
Place utility functions — geometry helpers, recursive searches, datum creators — between the imports and if __name__ == "__main__":. Keep them pure (no side effects, no global state).
All Part Document templates already include searchHybridBody and create_datum. Additional helpers (searchHybridBodyWithPath, collect_all_names, coordinate maths, get_path) are available in setup/templates/common_functions.py — copy what you need. See Common Functions for the full reference.
All CATIA interaction happens inside if __name__ == "__main__":. This is the standard Python pattern that prevents the code running when the file is imported, and is required for the app's hash check to work correctly.
Every template checks the active document type before doing any work and exits with a clear message if the wrong type is open.
The ScriptDialog class is defined before if __name__ == "__main__":. It reads saved settings on __init__ and exposes field values as instance attributes for the main block to read after ShowModal().
SETTINGS_DIR and SETTINGS_FILE are set at the top of if __name__ == "__main__":. See Writing Scripts#Persistent Data for the full pattern and rules.
| Marker | Meaning |
|---|---|
EDIT: |
Replace this value — it is wrong for your script as-is |
# TODO: |
Add your logic here |
#EDIT: |
Inline comment flagging a value that must be changed |
All EDIT: text in the header, dialog title, field labels, defaults, and SETTINGS_DIR name must be replaced before the script is usable.
- Copy the template file to the correct script folder (
Part_Document_Scripts/,Process_Document_Scripts/, etc.) - Rename it:
Snake_Case_Descriptive_Name.py - Update the metadata header —
Script name,Purpose,Author,Date,Description,dependencies,requirements - For persistence templates: change
Your_Script_NameinSETTINGS_DIRto match the exact filename (without.py) - Add your parameter fields to
ScriptDialog.__init__— duplicate theStaticText + TextCtrlrows and updatehardcoded_defaults - Update
on_resetto set every field back to its hardcoded default - Add your field names to
get_settings_to_save()(process persistence template) or the inlinejson.dumpdict (part persistence templates) - Replace the
# TODO:comment in the main block with your script logic - Add any pip packages required to
setup/requirements.txt - Test with CATIA V5 running and confirm the tooltip shows correctly in CatiaMenuWin32
See these scripts for complete real-world implementations of each pattern:
| Pattern | Example script |
|---|---|
| Part — dialog + persistence + progress | Involute Gear Generator |
| Process — dialog + persistence | Check Operation Parameters Against Limits |
| Process — basic | Export NC Program Names To CSV |
| Part — basic | Batch Isolate Geometric Set |
| Product — basic | Save Child Parts To STEP |
| Any — dialog | Find And Select By Name |
Getting Started
Contributing
- Batch CATDrawing To PDF
- Find And Select By Name
- Hide Planes And Axis Systems
- Rename Hybrid Shapes
- Replace Name Hybrid Shapes
- Toggle Show Hide Geometric Set
- 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
- Copy Geometric Set To New Part
- Create Construction Planes
- Create ISM OSM STEP Files
- Delete Deactivated Features
- Export All Parameters To CSV
- Export Curve Lengths Surface Areas To CSV
- Export Geometric Set Structure To CSV
- Export Mass CoG Inertia 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
- 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
- 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
- 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
- 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
- BOM Export To CSV
- Export Assembly As STEP
- Save Child Parts To STEP
Legal