-
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 |
| drawing_document_basic.py | CATDrawing | No | No | No |
| drawing_document_dialog.py | CATDrawing | 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 |
| Drawing — basic | Add Border And Title Block |
| Drawing — dialog | Update Title Block From Properties |
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