Examples

Simple examples that help you get started using pycatia.

For more complex scripts see the section on User Scripts.

Index

ASSEMBLY CONVERTOR EXAMPLES

BOM CUSTOM EXAMPLES

CONSTRAINTS EXAMPLES

DOCUMENT EXAMPLES

DRAFTING EXAMPLES

HUMAN MODELLING EXAMPLES

HYBRID BODIES EXAMPLES

HYBRID SHAPE FACTORY EXAMPLES

HYBRID SHAPE FACTORY & SHAPE FACTORY EXAMPLES

HYBRID SKETCH & SHAPE FACTORY EXAMPLES

INERTIA EXAMPLES

LICENSE SETTINGS EXAMPLES

LOGGING EXAMPLES

MATERIAL INTERFACES EXAMPLES

MESSAGE BOX EXAMPLES

PARAMETERS EXAMPLES

PRODUCT EXAMPLES

SELECTION EXAMPLES

SHAPE FACTORY EXAMPLES

SPACE ANALYSIS EXAMPLES

SPECS AND GEOMETRY WINDOW EXAMPLES

VISUAL PROPERTIES EXAMPLES

ASSEMBLY CONVERTOR EXAMPLES

Assembly Convertor - Example 1

Print the BOM of a product to XLS using the inbuilt AssemblyConvertor. You must already have excel installed.

This can also be used to create TXT and HTML files.

See github issue https://github.com/evereux/pycatia/issues/110 with regards to file paths and saying “No” to overwriting existing files and file paths when using excel. These issues are mitigated using the code below by checking for an existing excel file and removing it and also using pythons pathlib.Path module.

Asssembly Convetor - 001

BOM CUSTOM EXAMPLES

BOM Custom - Example 1

Write the contents of a product to a html file.

BOM Custom - 001

CONSTRAINTS EXAMPLES

Constraints - Example 1

Fix the first Sub Product in Product using constraints. The Sketch examples also show further usage of constraints.

Constraints - 001

DOCUMENT EXAMPLES

Document - Example 1

Use the context manager to open CATIA documents and close.

Document - 001

Document - Example 2

Open all CATParts in source directory and save to IGS in target directory.

Document - 002

Document - Example 3

Open a catia file.

Export catia file to STP.

Close a catia file.

Document - 003

DRAFTING EXAMPLES

Drafting - Example 1

Drafting: create a border template in the background view of the currently opened A0 landscape CATDrawing.

Drafting - 001

HUMAN MODELLING EXAMPLES

Human Modelling - Example 1

Add a female manikin to the product in the sitting position.

Human Modelling - 001

HYBRID BODIES EXAMPLES

Hybrid Bodies - Example 1

Make body in work object and intersect with another body.

Hybrid Bodies - 001

HYBRID SHAPE FACTORY EXAMPLES

Hybrid Shape Factory - Example 1

Sequentially rename all points in geometric set (hybrid body) Points in the geometric set MasterGeometry.

Hybrid Shape Factory - 001

Hybrid Shape Factory - Example 2

Reads a csv file containing point data and adds to the new catia part.

Formatting of csv data should be:

<point_name>,<x coordinate>,<y coordinate>,<z coordinate>

Hybrid Shape Factory - 002

Hybrid Shape Factory - Example 3

Draw a line between two points.

Hybrid Shape Factory - 003

Hybrid Shape Factory - Example 4

Loops through the items in hybrid body “Lines” and determine the object type using selection.

Once determined create an object from it and find it’s parent(s)

Requires an active part document open with a geometrical set called “construction_geometry” containing points generated using HybridShapePtCoord and line generated using HybridShapeLinePtPt

Hybrid Shape Factory - 004

Hybrid Shape Factory - Example 5

GSD: Split a surface using a plane.

Requirements: Geometrical set named “ConstructionGeometry”. A surface within the geometrical set called “Surface.1” that can be split by the origin ZX plane.

Hybrid Shape Factory - 005

Hybrid Shape Factory - Example 6

How to add a new sphere when a reference axis system isn’t required.

Requirements: A geometrical set named “ConstructionGeometry”. A point within the ConstructionGeometry named “Point.1”.

Hybrid Shape Factory - 006

HYBRID SHAPE FACTORY & SHAPE FACTORY EXAMPLES

Hybrid Shape Factory & Shape Factory - Example 1

3D Points, Spline, Extrusion and Generate Thickness.

Hybrid Shape Factory & Shape Factory - 001

HYBRID SKETCH & SHAPE FACTORY EXAMPLES

Hybrid Sketch & Shape Factory - Example 1

Creates a square in a sketch and fully constrains it. Sketch then used to pad.

Hybrid Sketch & Shape Factory - 001

INERTIA EXAMPLES

Inertia - Example 1

Measure Inertia of MainBody in CATPArt.

Inertia - 001

LICENSE SETTINGS EXAMPLES

License Settings - Example 1

Basic license checking.

License Settings - 001

LOGGING EXAMPLES

Logging - Example 1

Logging.

Logging - 001

MATERIAL INTERFACES EXAMPLES

Material - Example 1

CATMatInterfaces

Opens the material catalog and retrieves the first few materials.

Creates a new part and applies the material to the part, the main body and a hybrid body.

Creates a new product and applies the material to it.

Material - 001

MESSAGE BOX EXAMPLES

Message Box - Example 1

This creates a message box with the buttons abort, retry ignore and displays the Warning Query icon.

Message Box - 001

PARAMETERS EXAMPLES

Parameters - Example 1

Access the CATIA COM object with a .CATPart open and and display each parameter along with its name, value and its associated parameter set.

# todo: need to create a source part to support this example.

Parameters - 001

Parameters - Example 2

Change the Length value of parameter named Thickness.

Parameters - 002

PRODUCT EXAMPLES

Product - Example 1

Warning

With regards to pycatia this example only shows how to select the root product. The rest is handled by pywinauto. _https://pywinauto.github.io/

You will need to manually install package pywinauto to run this script. Also, the placement of from pywinauto import Desktop is important.

Assembly Design: Reorder a Product tree alphabetically. The Product shall already be loaded.

Product - 001

Product - Example 2

Move the first child in product.

Product - 002

Product - Example 3

Loop through a CATProduct and analyse children if CATPart.

Only goes two levels deep.

Product - 003

Product - Example 4

Get the position matrix of products (CATPart or CATProduct) in product.

Product - 004

Product - Example 5

Loop through a CATProduct and find if sub component is a CATPart or CATProduct.

Product - 005

Product - Example 6

Get the Inertia of a product using product.get_technical object and print it’s mass.

Product - 006

SELECTION EXAMPLES

Selection - Example 1

Prompt the user to select a product and get it’s bounding box parameters

Warning

Currently there must be NO other existing Measure Inertias saved ANYWHERE in your product tree as these may be returned and not product you have selected.

Selection - 001

Selection - Example 2

Usage of the Selection.select_element2 class method which accepts two selection inputs.

Selection - 002

Selection - Example 3

Usage of the Selection.select_element2 to select a geometrical feature and report it’s properties in a message window.

Selection - 003

SHAPE FACTORY EXAMPLES

Shape Factory - Example 1

Add new bodies to part. Create a cylinder in an added body. Do Intersection operations between two bodies..

Shape Factory - 001

Shape Factory - Example 2

Mirror the main body of the part using shape_factory.add_new_symmetry_2. Shape Factory - 002

SPACE ANALYSIS EXAMPLES

Space Analysis - Example 1

Get the center of gravity for the part body ‘PartBody’.

Space Analysis - 001

Space Analysis - Example 2

Get all the points in the geometrical set ‘Points’ and output co-ordinate to console.

Create your own CATPart with a Geometrical Set called construction_points. Add some points to the Geometrical Set.

Space Analysis - 002

Space Analysis - Example 3

Find all points in the CATPart and print to console and export to csv.

Example 3

SPECS AND GEOMETRY WINDOW EXAMPLES

Specs And Geometry Window - Example 1

Loop through all the CATParts in a directory and save PLAN VIEW, SIDE VIEW, END VIEW and ISO pngs for each part.

The tree is turned off and the background turned white for the screen capture and then turned back on.

Specs And Geometry Window - 001

VISUAL PROPERTIES EXAMPLES

Visual Properties - Example 1

Searching and changing visual properties. Find all Red points and make them Pink.

Visual Properties - 001