Python library for Dassault Systemes CATIA

There are already some examples on this website, which explain, how to automate Dassault Systemes CATIA V5 with Python and Microsoft COM. Yesterday Paul sent me a mail and mentioned, that he has created a Python Library, which packs a few of the COM magics into a Python library with some basic functions. It covers things like, traversing assembly structures, context manager, convert files, find elements in a part, etc.

Here is an example:

from pycatia import CATIAApplication

catia = CATIAApplication()

documents = catia.documents()
documents.open(r'tests\CF_TopLevelAssy.CATProduct')

document = catia.document()
product = document.product()
products = product.get_products()

if len(products) == 0:
    print("Active document has no children or is not a CATProduct.")

for item in product.get_products():

    if item.is_catpart():
        print(f'This is a part: "{item}"')
        print('')

    if item.is_catproduct():
        product = item
        print(f'This is a product: "{item}"')

        if item.has_children():
            print('This product has children.')
            children = item.get_children()
            print(children)
        print('')

You can find pycatia on http://pypi.org/project/pycatia/ or onĀ https://github.com/evereux/pycatia.

Or you can directly install it via pip in Python 3.6 by:

pip install pycatia

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.