RSS category feeds

RSS site feeds


How to automate CATIA V5 with Python on Windows PDF Print E-mail

If you want to automate CATIA V5 with Python you need Pywin32 and Python for Windows. Python is free software and you can develop professional applications with all advantages of Python for CATIA V5. And you can deploy your applications as a standard Windows executable what you cannot do with the builtin Macro language VB.

For developing a small application which interacts to CATIA V5 you only have to download Python for Windows and Pywin32 from Marc Hammond (please see the Download section). CATIA V5 must be also installed and should be running when testing the application.

If you have done that you can test it with this source code:

import win32com.client
a = win32com.client.Dispatch('catia.application')
for i in range(doc.Products.Count):
    print 'Part Number:', doc.Products.Item(i+1).PartNumber

It prints out the part names of a loaded CATProduct. Other examples can be found in the script collection.

Hint: You can automate DMU Navigator as well as CATIA V5 with this Dispatch string:

a = win32com.client.Dispatch('DMU.application')

Important notes:

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 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). Not for the "CATIA V5 Interfaces Objekt Library"!

But if you have done that stupidly, 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).

For starting developing applications with Python for CATIA V5 you should use the manual V5Automation.chm which you can find in the bin-directory of CATIA V5. You will see that you can develop Python applications in the same way like VB with the builtin VB editor.

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...

More information for developing with Python for COM applications with Pywin32 you can find in this excellent book. A whole example Chapter about COM Programming with Python/Pywin32 can be found here.

Python Programming on Win32
by Mark Hammond, Andy Robinson
ISBN: 1-56592-621-8
652 pages. January 2000.

Last Updated ( Wednesday, 06 June 2007 )
< Prev




  • hey how can we clear history of a single skype group ? any idea? More...
  • Dear Brent I'm trying to get the points coordinate in a PYTHON/CATIA macro but I... More...
  • Hi Brent, I'm trying to create a macro for create the best fitting circle given... More...
  • I have run your code on my own machine, but I just got the last paragraph of the... More...
  • Hello Gabriel, It seem that the linked site moved to (... More...

Login Form

Lost Password?

My prefered Python IDE

My prefered Python editor is Pyscripter from MMExperts. It is not only an editor. Pyscripter is a full Python IDE including (remote) debugging, a class browser, and all other nice helpers which a full featured IDE needs.

Do you have a script for me ?

Do you have an interesting Python script which does some really cool thing on Windows ? Please post them to this site. It`s very simple - simply copy&paste it to this form. No login is requiered.

Hint: For syntax highlighting and correct Python intendation place your code between html tags <pre> and </pre>.

My prefered web framework

My prefered web framework for developing web applications is Django. Django calls itself The web framework for perfectionists with deadlines. It is a really fast, scalable and (thanks Python) the sexiest web framework of the world.