Welcome, guest | Sign In | My Account | Store | Cart

This is small application shows how to automate the CAD/PLM Software CATIA V5 via win32com. CATIA V5 must be installed and should be running when testing the application. Other examples you can find on http://win32com.goermezer.de/content/view/29/291/ .

Python, 15 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import win32com.client
catapp = win32com.client.Dispatch("CATIA.Application")
doc=catapp.ActiveDocument.Product

product_count = doc.Products.Count
print "This example lists all Parts and Subproducts of the first level from a CATProduct."
for products in range(product_count):
    products = products + 1
    print doc.Products.Item(products).Name, ":"
    part_count = doc.Products.Item(products).Products.Count
    for parts in range(part_count):
        parts = parts +1
        print "   ", doc.Products.Item(products).Products.Item(parts).Name

#For aHTML-generated Bill of Material you should use doc.Product.ExtractBOM(2, 'c:\\BOM.html') 

If you want to use early binding for the CATIA V5 object libraries you can use the Makepy utility from Pythonwin. After that every object and its methods will be usable from the pulldown menu of Pythonwin while typing and you can have a performance advantage. You should use makepy for every object library which you want to use e.g. "ProductStructure Object Library" for working with CATProducts). But not for the "CATIA V5 Interfaces Objekt Library"!

If you do that every application which uses early binding for the "CATIA V5 Interfaces Objekt Library" will not work ! A workaround is not to use makepy for the "CATIA V5 Interfaces Objekt Library" or use explicit late binding "(import win32com.client.dynamic as the first line).

If you have problems to access the COM Interface from CATIA V5 (eg. no object libraries from CATIA V5 in makepy) please check whether CATIA V5 was registrated as a COM server. If not you can do that with cnext.exe /regserver in the CATIA V5 bin-directory. Then everything should work well...

1 comment

sarah 12 years, 10 months ago  # | flag

Hello every body,

Thank you for this example that runs very good...

I have two questions and I hope that you could help me ... :)

1- I want to write the result of print (of the example above) in word and I don't know how to do it (book.Content.Text = ? "

2- Can I do communication between SPEOS (a photometric software integrated into CATIA V5)and python?

I am in need of your Help !!!

Tank you very much

Best regards

Saimyas

Created by Mustafa Görmezer on Tue, 23 Nov 2004 (PSF)
Python recipes (4591)
Mustafa Görmezer's recipes (2)

Required Modules

Other Information and Tasks