Python Module for CATIA V5

While many code examples here elaborate on automating CATIA V5 with pywin32, Paul Bourne has created the pycatia module to simplify the usage of CATIA in Python. I like that approach very much because it enables  people to use CATIA and Python even in a  professional environment.

With pywin32 or comtypes I remember some very tricky situations with the data types in CATIA. This module tries to solve these issues by utilizing VBA under the hood. An interesting approach!

Paul still classifies the module as alpha. But the likes on Github show the right direction. Good luck Paul.

Working with ByRef arrays in CATIA

This is not actually a script, but a solution I’ve found to a huge roadblock I encountered while trying to use Python to automate CATIA V5 using win32com AND use all funcionalities exposed to automation.

We all know it’s very easy to get started by just using late-binding (dynamic dispatch) and the more advanced users will already know that it will be not possible to use Subs that need Byref arrays. Developers of win32com related stuff are aware of the problem but not to the fact that in some applications these kind of Sub are very intensively used i.e. all subs to get triplets such as GetCoordinates of any class derived from the Point class, or GetFirstAxis of any class derived from the Plane class.
Developers state that it’s sufficient to switch to early bindig using makepy to solve the problem but in my case for CATIA V5 R19 it didn’t solve the problem at all, it even added more problems. Continue reading “Working with ByRef arrays in CATIA”

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. Continue reading “Python library for Dassault Systemes CATIA”

A batch script to convert CAD files with CATIA V5

import os, sys
import win32com.client


def convert(file, format):

    print '  Converting with CATIA V5'
    dirname, filename = os.path.split(file)
    basename, ext = os.path.splitext(filename)
    fileout=os.path.join(dirname, basename + '.' + format)
    try:
        CATIA = win32com.client.Dispatch('CATIA.Application')
    except:
        print 'Error connecting to CATIA! Either CATIA V5 is not installed or' \
        'you didn`t have registered CATIA V5 as a COM application.'
        print 'You can do this with:'
        print '   >> c:\\...\\Dassault Systemes\\intel_a\\code\\bin\\CNEXT.exe /regserver'
        sys.exit()
    CATIA.DisplayFileAlerts = False
    Doc = CATIA.Documents.Open(os.path.abspath(file))
    try:
        Doc.ExportData(fileout, format)
    except:
        print 'Could not convert file %s.'%file
    finally:
        Doc.Close()
        CATIA.Quit()
    print 'done'
    return fileout

if __name__ == "__main__":
    if len(sys.argv)==1:
        print 'Usage: v5batcher.py [filename] [format]'
    else:
        convert(sys.argv[1], sys.argv[2])


Automated generation of a simplified drive shaft

This script creates a new CATPart including parameters, design table, rules and checks (Knowledge Advisor).

The script runs with CATIA V5 Release R15 (R14 needs minor changes in code). It supports user interface languages english and german. The code is well commented, but comments are all in german. For some more informations, look at the short documentation (german).

import win32com.client  #Modul für COM-Client
import sys, os  #Für File-Handling
import win32gui #Für MessageBox

CATIA = win32com.client.Dispatch("CATIA.Application")


#Daten für Konstruktionstabelle 'Passfeder DIN 6885'
dmin=[8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.,
      10., 10., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 17., 17., 17., 17., 17.,
      17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22.,
      22., 22., 22., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 30., 38., 38., 38., 38.,
      38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44.,
      44., 44., 44., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 58., 58., 58., 58., 58., 58.,
      58., 58., 58., 58., 58., 58., 58., 65., 65., 65., 65., 65., 65., 65., 65., 65., 65., 65., 65., 65., 75., 75.,
      75., 75., 75., 75., 75., 75., 75., 75., 75., 75., 75., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85.,
      85., 85., 95., 95., 95., 95., 95., 95., 95., 95., 95., 95., 95., 95., 95., 110., 110., 110., 110., 110., 110.,
      110., 110., 110., 110., 110., 110., 110., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130.,
      130.]
dmax=[10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 12., 12., 12., 12., 12., 12., 12., 12., 12.,
      12., 12., 12., 12., 12., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 17., 22., 22.,
      22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 30., 30., 30., 30., 30., 30., 30., 30., 30.,
      30., 30., 30., 30., 30., 30., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 38., 44.,
      44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 44., 50., 50., 50., 50., 50., 50., 50., 50.,
      50., 50., 50., 50., 50., 50., 58., 58., 58., 58., 58., 58., 58., 58., 58., 58., 58., 58., 58., 65., 65., 65.,
      65., 65., 65., 65., 65., 65., 65., 65., 65., 65., 75., 75., 75., 75., 75., 75., 75., 75., 75., 75., 75., 75.,
      75., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85., 85., 95., 95., 95., 95., 95., 95., 95., 95.,
      95., 95., 95., 95., 95., 110., 110., 110., 110., 110., 110., 110., 110., 110., 110., 110., 110., 110., 130.,
      130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 150., 150., 150., 150., 150., 150.,
      150., 150., 150., 150., 150., 150., 150.]
b=[3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 5.,
   5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 8.,
   8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 8., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 10.,
   10., 10., 10., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 14., 14., 14., 14., 14.,
   14., 14., 14., 14., 14., 14., 14., 14., 14., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 16., 18.,
   18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20., 20.,
   20., 20., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 22., 25., 25., 25., 25., 25., 25., 25., 25.,
   25., 25., 25., 25., 25., 28., 28., 28., 28., 28., 28., 28., 28., 28., 28., 28., 28., 28., 32., 32., 32., 32., 32.,
   32., 32., 32., 32., 32., 32., 32., 32., 36., 36., 36., 36., 36., 36., 36., 36., 36., 36., 36., 36., 36.]
t=[1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5,
   2.5, 2.5, 2.5, 2.5, 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3., 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5,
   3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 4., 5., 5., 5., 5.,
   5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.5, 5.5,
   5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 5.5, 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 6., 7.,
   7., 7., 7., 7., 7., 7., 7., 7., 7., 7., 7., 7., 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 9.,
   9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 9., 10., 10., 10.,
   10., 10., 10., 10., 10., 10., 10., 10., 10., 10., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11., 11.,
   12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12., 12.]
l=[6., 8., 10., 12., 14., 16., 18., 20., 22., 25., 28., 32., 36., 8., 10., 12., 14., 16., 18., 20., 22., 25., 28., 32.,
   36., 40., 45., 10., 12., 14., 16., 18., 20., 22., 25., 28., 32., 36., 40., 45., 50., 56., 14., 16., 18., 20., 22.,
   25., 28., 32., 36., 40., 45., 50., 56., 63., 70., 18., 20., 22., 25., 28., 32., 36., 40., 45., 50., 56., 63., 70.,
   80., 90., 22., 25., 28., 32., 36., 40., 45., 50., 56., 63., 70., 80., 90., 100., 110., 28., 32., 36., 40., 45., 50.,
   56., 63., 70., 80., 90., 100., 110., 125., 140., 36., 40., 45., 50., 56., 63., 70., 80., 90., 100., 110., 125.,
   140., 160., 45., 50., 56., 63., 70., 80., 90., 100., 110., 125., 140., 160., 180., 50., 56., 63., 70., 80., 90.,
   100., 110., 125., 140., 160., 180., 200., 56., 63., 70., 80., 90., 100., 110., 125., 140., 160., 180., 200., 220.,
   63., 70., 80., 90., 100., 110., 125., 140., 160., 180., 200., 220., 250., 70., 80., 90., 100., 110., 125., 140.,
   160., 180., 200., 220., 250., 280., 80., 90., 100., 110., 125., 140., 160., 180., 200., 220., 250., 280., 320., 90.,
   100., 110., 125., 140., 160., 180., 200., 220., 250., 280., 320., 360., 100., 110., 125., 140., 160., 180., 200.,
   220., 250., 280., 320., 360., 400.]

#Koordinaten für 2D-Geometrie, Welle + Passfedernut
# 0-7 Welle , 8-13 Passfedernut
x=[0.,0.,60.,60.,150.,150.,190.,190.,75.,75.,75.,125.,125.,125.]
y=[0.,15.,15.,25.,25.,18.,18.,0.,-7.,0.,7.,7.,0.,-7.]

PI=3.141592658

#Konstruktionstabelle 'Passfeder' erstellen
file=open("Passfeder.txt", "w")
file.write("dmin(mm)\tdmax(mm)\tbreite(mm)\ttiefe(mm)\tlaenge(mm)\n")
for i in range(len(dmin)):
    file.write(str(dmin[i])+"\t"+str(dmax[i])+"\t"+str(b[i])+"\t"+str(t[i])+"\t"+str(l[i])+"\n")
file.close()
Path=os.getcwd()                #Aktuellen Dateipfad speichern
FullPath=Path+"\Passfeder.txt"  #Pfad mit Dateinamen für Übergabe an CATIA

# Funktion zur Anpassung der Befehle an Umgebungssprache von CATIA (deutsch/englisch)
# Übergeben wird der im Quellcode verwendete englische Befehl
def trans(Command):
    "Übersetzt sprachspezifische Befehle für deutsche und englische Benutzerumgebung."
    translation={'Sketch':'Skizze','Exit workbench':'Umgebung verlassen','Sketch':'Skizze','Update':'Aktualisieren',
                 'AbsoluteAxis':'Absolute Achse',
         'HDirection':'H-Richtung','VDirection':'V-Richtung','PartBody':u'Hauptkörper','Shaft':'Welle','Length':u'Länge'}
    if language=="Englisch":
        result=Command  #Keine Änderung
    else:               #Deutsch
        result=translation[(Command)] #Deutschen Befehl zurückgeben
    return result

#CATIA ausblenden, Performancesteigerung, 'Kosmetik'
CATIA.Visible = False

# Neues CATPart erstellen
MyNewDoc=CATIA.Documents.Add("Part")    #"Part"=CATPart, "Product"=CATProduct
MyDoc=CATIA.ActiveDocument              #Aktives CATIA-Dokument
MyPart=MyDoc.Part                       #CATPart vom aktiven Dokument
MyBodies=MyPart.Bodies                  #MyBodies=Listenobjekt aller Körper
MyBody=MyBodies.Item(1) #Körper deklarieren (1)=Hauptkörper bzw. PartBody, (2)=nächster Körper im Baum

# Bei Eingabe von Namen, auf vorhandenen Namen prüfen und ggf. korrekten Indize vergeben 
tempname = raw_input("Name für neues\t CATPart: \n(leer = Standardname)")
num=CATIA.ActiveDocument.GetItem(MyNewDoc)  #index des neu geöffneten Parts
if len(tempname)<>0:                        #Eigenen Namen vergeben
    counter=1
    check=0
    newname=tempname
    while check0:                 #Check auf Namensgleichheit für alle offenen Dokumente durchlaufen
                    newname=tempname        #Namen übernehmen
                check=0                     #Durchlaufcheck reset
                counter=counter+1           #Zähler inkrementieren (MeinPart & MeinPart_1 vorhanden --> Zähler auf 2)
                newname=tempame+"_"+str(counter)
        check=check+1                       #Durchlaufcheck inkrementieren
    num.PartNumber=newname                  #Eigenen Namen an neues Part vergeben
else:                                       #Keine Eingabe --> Standardname vergeben
    newname = num.PartNumber                #Standardname in newname speichern

#Umgebungssprache feststellen (s. Funktion trans)
if MyBody.Name=="PartBody":         #Einfache (Einzige?) Möglichkeit festzustellen unter welcher Sprache CATIA läuft
    language="Englisch"
elif MyBody.Name==u"Hauptkörper":   #u".."= unicode-String (sonst keine Umlaute)
    language="Deutsch"
else:   #Fehlermeldung ausgeben, da Sprache nicht unterstützt wird
    print"Benutzersprache von CATIA wird nicht unterstützt, bitte auf Englisch oder Deutsch einstellen"
    win32gui.MessageBox(0, "Die gewählte Umgebungssprache von CATIA wird nicht unterstützt"+chr(13)+
                        "Bitte auf Deutsch oder Englisch einstellen", "Programmabbruch", 16)
    CATIA.Visible = True    #CATIA wieder einblenden
    sys.exit()              #Programm beenden    
    
#Sketcher öffnen
MySketches=MyBody.Sketches                  #Listenobjekt aller Skizzen
MyOriginElements=MyPart.OriginElements      #Ursprungselemente deklarieren (Achsen,Koord.Urspr.)
MyReference=MyOriginElements.PlaneXY        #Referenz der XY-Ebene erzeugen
MySketch=MySketches.Add(MyReference)        #Skizze auf XY-Ebene erzeugen
MySel=MyDoc.Selection                       #Objekt MySel der Klasse Selection erzeugen (Auswahl)
MySel.Add(MySketch)                         #XY-Ebene zur Auswahl hinzufügen (entspricht dem anklicken der Ebene)
CATIA.StartCommand(trans('Sketch'))         #Sketcher Workbench starten
KSS=[0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0]   #[1-3] = Koord.Ursprung, [4-6] und [7-9] Vektoren der Achsrichtungen
MySketch.SetAbsoluteAxisData(KSS)           #Koordinatensystem zuweisen

#
#2D Geometrie Welle erzeugen
#
MySketch.OpenEdition                        #Skizze "intern" für Bearbeitung öffnen (läuft auch ohne!?)
MyGeo1 = MySketch.GeometricElements         #Achsen deklarieren für späteren Bezug durch Constraints
Axis = MyGeo1.Item(trans("AbsoluteAxis"))
AxisH = Axis.GetItem(trans("HDirection"))
AxisV = Axis.GetItem(trans("VDirection"))
factory2D1 = MySketch.Factory2D             #Klasse Factory2D stellt Methoden zur Definition von Geometrie bereit
#Punkte Welle
PW0 = factory2D1.CreatePoint(x[0],y[0])     #Punkte für Skizzengeometrie der Welle erzeugen
PW1 = factory2D1.CreatePoint(x[1],y[1])
PW2 = factory2D1.CreatePoint(x[2],y[2])
PW3 = factory2D1.CreatePoint(x[3],y[3])
PW4 = factory2D1.CreatePoint(x[4],y[4])
PW5 = factory2D1.CreatePoint(x[5],y[5])
PW6 = factory2D1.CreatePoint(x[6],y[6])
PW7 = factory2D1.CreatePoint(x[7],y[7])
#Punkte Achse
PA0 = factory2D1.CreatePoint(x[0],y[0]) 
PA1 = factory2D1.CreatePoint(x[7],y[7])
#Linien Welle
LW1 = factory2D1.CreateLine(x[0], y[0], x[1], y[1]) #Linien erzeugen
LW1.StartPoint = PW0                                #Start- und Ende der Linie mit den erzeugten Punkten verbinden
LW1.EndPoint = PW1
LW2 = factory2D1.CreateLine(x[1], y[1], x[2], y[2])
LW2.StartPoint = PW1
LW2.EndPoint = PW2
LW3 = factory2D1.CreateLine(x[2], y[2], x[3], y[3])
LW3.StartPoint = PW2
LW3.EndPoint = PW3
LW4 = factory2D1.CreateLine(x[3], y[3], x[4], y[4])
LW4.StartPoint = PW3
LW4.EndPoint = PW4
LW5 = factory2D1.CreateLine(x[4], y[4], x[5], y[5])
LW5.StartPoint = PW4
LW5.EndPoint = PW5
LW6 = factory2D1.CreateLine(x[5], y[5], x[6], y[6])
LW6.StartPoint = PW5
LW6.EndPoint = PW6
LW7 = factory2D1.CreateLine(x[6], y[6], x[7], y[7])
LW7.StartPoint = PW6
LW7.EndPoint = PW7
#Linie Achse
LA = factory2D1.CreateLine(x[0], y[0], x[7], y[7])
LA.StartPoint = PA0
LA.EndPoint = PA1
MySketch.CenterLine = LA                        #Linie als Achse definieren

#Constraints
#Constraints können nur an Referenzen der Objekte zugewiesen werden
MyCons=MySketch.Constraints                     #Listenelement Constraints
RLA = MyPart.CreateReferenceFromObject(LA)      #Referenz der Achse
CLA = MyCons.AddMonoEltCst(10,RLA)              #..Mono.. = verarbeitet 1 Referenz, 10 = Horizontal
#Constraints Horizontal/Vertikal
RLW1 = MyPart.CreateReferenceFromObject(LW1)
CLW1 = MyCons.AddMonoEltCst(13,RLW1)            #13 = Vertikal
RLW2 = MyPart.CreateReferenceFromObject(LW2)
CLW2 = MyCons.AddMonoEltCst(10,RLW2) 
RLW3 = MyPart.CreateReferenceFromObject(LW3)
CLW3 = MyCons.AddMonoEltCst(13,RLW3) 
RLW4 = MyPart.CreateReferenceFromObject(LW4)
CLW4 = MyCons.AddMonoEltCst(10,RLW4)
RLW5 = MyPart.CreateReferenceFromObject(LW5)
CLW5 = MyCons.AddMonoEltCst(13,RLW5) 
RLW6 = MyPart.CreateReferenceFromObject(LW6)
CLW6 = MyCons.AddMonoEltCst(10,RLW6)
RLW7 = MyPart.CreateReferenceFromObject(LW7)
CLW7 = MyCons.AddMonoEltCst(13,RLW7)
#Constraints Koinzidenz Punkte/Achse
RPW0 = MyPart.CreateReferenceFromObject(PW0)
CPW0_LA0 = MyCons.AddBiEltCst(2,RPW0,RLA)       #..Bi.. = 2 Referenzen, 2 = Koinzidenz
RPW7 = MyPart.CreateReferenceFromObject(PW7)
CPW7_LA0 = MyCons.AddBiEltCst(2,RPW7,RLA)
#Constraints Dimension Durchmesser
CDLW2_rad = MyCons.AddBiEltCst(26, RLA, RLW2)   #26 = Bemaßung Radius
CDLW2_rad.Mode = 0                              #Mode 0 = Driving Dimension, Mode 1= Driven Dimension
DLW2_rad = CDLW2_rad.Dimension
DLW2_rad.Value = y[2]
CDLW4_rad = MyCons.AddBiEltCst(26, RLA, RLW4)
CDLW4_rad.Mode = 0
DLW4_rad = CDLW4_rad.Dimension
DLW4_rad.Value = y[4]
CDLW6_rad = MyCons.AddBiEltCst(26, RLA, RLW6)
CDLW6_rad.Mode = 0
DLW6_rad = CDLW6_rad.Dimension
DLW6_rad.Value = y[6]
#Constraints Dimension Längen
CDLW2_len = MyCons.AddMonoEltCst(5, RLW2)       #5 = Bemaßung Länge
CDLW2_len.Mode = 0
DLW2_len = CDLW2_len.Dimension
DLW2_len.Value=abs(x[1]-x[2])
CDLW4_len = MyCons.AddMonoEltCst(5, RLW4)
CDLW4_len.Mode = 0
DLW4_len = CDLW4_len.Dimension
DLW4_len.Value=abs(x[3]-x[4])
CDLW6_len = MyCons.AddMonoEltCst(5, RLW6)
CDLW6_len.Mode = 0
DLW6_len = CDLW6_len.Dimension
DLW6_len.Value=abs(x[5]-x[6])
#Constraints Position der Skizze an KS fixieren
RAxisV = MyPart.CreateReferenceFromObject(AxisV)        #KS-Achse-Vertikal
CLW1_AxisV = MyCons.AddBiEltCst(2,RLW1,RAxisV)          #Constr. Welle links Koinzident mit senkrechter KS-Achse
RAxisH = MyPart.CreateReferenceFromObject(AxisH)        #KS-Achse-Horiz.
CLA_AxisH = MyCons.AddBiEltCst(2,RLA,RAxisH)            #Constr. WellenAchse Koinzident zur waagerechten KS-Achse

MySketch.CloseEdition                                   #Skizze "intern" schließen
CATIA.StartCommand(trans("Exit workbench"))             #Entspr. Klick auf "Umgebung verlassen"


#Körper durch Rotation
MyShapeFactory=MyPart.ShapeFactory
MyShape=MyShapeFactory.AddNewShaft(MySketch)            #'Welle' hinzufügen auf Skizzenbasis MySketch
MyParas=MyPart.Parameters                       
PShaft1=MyParas.Item(newname+"\\"+trans("PartBody")+"\\"+trans("Shaft")+".1\ThickThin1")    #Parameter1 für Welle
PShaft1.Value=1.                                                                            #Wert zuweisen
PShaft2=MyParas.Item(newname+"\\"+trans("PartBody")+"\\"+trans("Shaft")+".1\ThickThin2")    #Parameter2 für Welle
PShaft2.Value=0.                                                                            #Wert zuweisen

CATIA.StartCommand(trans("Update"))     #Aktualisieren
MySel.Clear()                           #Auswahl aufheben (=demarkieren)
#
#Sketch.2 erstellen für Passfeder
#
MyPart.InWorkObject=MyBody              #Objekt in Bearbeitung definieren
MySketch2=MySketches.Add(MyReference)   #-> Siehe MySketch oben
MySel=MyDoc.Selection
MySel.Add(MySketch2)
CATIA.StartCommand(trans("Sketch"))
MySel.Clear()
factory2D1 = MySketch2.Factory2D
MyCons=MySketch2.Constraints
MySketch2.OpenEdition()
#
# 2D Geometrie Passfedernut erzeugen
#
#Punkte
PP0 = factory2D1.CreatePoint(x[8], y[8])    #Kreis Anfangs-,Mittel-, und Endpunkte für Langlochgeometrie
PP1 = factory2D1.CreatePoint(x[9], y[9])
PP2 = factory2D1.CreatePoint(x[10], y[10])
PP3 = factory2D1.CreatePoint(x[11], y[11])
PP4 = factory2D1.CreatePoint(x[12], y[12])
PP5 = factory2D1.CreatePoint(x[13], y[13])
#Radius1 (Links)
RadP1 = factory2D1.CreateCircle(x[8], y[9], y[10]-y[9], PI/2.,PI*1.5)   #Kreisbogen zeichnen
RadP1.CenterPoint = PP1
RadP1.StartPoint = PP2
RadP1.EndPoint = PP0
#Linie1 (Oben)
LP1 = factory2D1.CreateLine(x[10],y[10],x[11],y[11])
LP1.StartPoint = PP2
LP1.EndPoint = PP3
#Radius2 (Rechts)
RadP2 = factory2D1.CreateCircle(x[12],y[12], y[11]-y[12], PI*1.5, PI*2.5)
RadP2.CenterPoint = PP4
RadP2.StartPoint = PP5
RadP2.EndPoint = PP3
#Linie2 (Unten)
LP2 = factory2D1.CreateLine(x[13],y[13],x[8],y[8])
LP2.StartPoint = PP5
LP2.EndPoint = PP0

#Constraints Passfedernut
MyGeo2 = MySketch2.GeometricElements
Axis2 = MyGeo2.Item(trans("AbsoluteAxis"))
AxisH2 = Axis2.GetItem(trans("HDirection"))
AxisV2 = Axis2.GetItem(trans("VDirection"))
#Linie 1 Horizontal (Unten)
RLP1 = MyPart.CreateReferenceFromObject(LP1)
CLP1 = MyCons.AddMonoEltCst(10, RLP1)
#Linie 2 Horizontal (Oben)
RLP2 = MyPart.CreateReferenceFromObject(LP2)
CLP2 = MyCons.AddMonoEltCst(10, RLP2)
#Linie1+Radius1 Tangential (Links Unten)
RRadP1 = MyPart.CreateReferenceFromObject(RadP1)
CRadP1_LP1 = MyCons.AddBiEltCst(4,RLP1,RRadP1)          #Constraint 4 = Tangential
#Linie2+Radius1 Tangential (Links Oben)
CRadP1_LP2 = MyCons.AddBiEltCst(4,RLP2,RRadP1)
#Linie1+Radius2 Tangential (Rechts Unten)
RRadP2 = MyPart.CreateReferenceFromObject(RadP2)
CRadP2_LP1 = MyCons.AddBiEltCst(4,RLP1,RRadP2)
#Linie2+Radius2 Tangential (Rechts Oben)
CRadP2_LP2 = MyCons.AddBiEltCst(4,RLP2,RRadP2)
#MittellPunkt Nut-Radius auf WellenAchse legen
RPP1 = MyPart.CreateReferenceFromObject(PP1)
RAxisH2 = MyPart.CreateReferenceFromObject(AxisH2)
CPP1_AxisH2 = MyCons.AddBiEltCst(2,RPP1,RAxisH2)
#Langloch position auf LängsAchseWelle
RAxisV2 = MyPart.CreateReferenceFromObject(AxisV2)
CDPP1_AxisV2 = MyCons.AddBiEltCst(1, RAxisV2,RPP1)
CDPP1_AxisV2.Mode = 0
DPP1_AxisV2 = CDPP1_AxisV2.Dimension
DPP1_AxisV2.Value = 85.
#Langloch Breite
CDLP1_LP2 = MyCons.AddBiEltCst(1,RLP1, RLP2)
CDLP1_LP2.Mode = 0
DLP1_LP2 = CDLP1_LP2.Dimension
DLP1_LP2.Value = 10.
#Langloch Länge (Tragende Länge der Passfeder , MitteRadius-MitteRadius)
RPP4 = MyPart.CreateReferenceFromObject(PP4)
CDPP1_PP4 = MyCons.AddBiEltCst(1,RPP1, RPP4)
CDPP1_PP4.Mode = 0
DPP1_PP4 = CDPP1_PP4.Dimension
DPP1_PP4.Value = 40.

MySketch2.CloseEdition()                        #Skizzieren abschließen
CATIA.StartCommand(trans("Exit workbench"))     #Skizziermodus verlassen

#
#Passfedernut (Tasche) erzeugen
#
MyPocket=MyShapeFactory.AddNewPocket(MySketch2, 10.)    #Tasche auf Skizzenbasis MySketch2
limit1 = MyPocket.FirstLimit                            # 1. Begrenzung
limit1.LimitMode = 2                                    #catUpToLastLimit (Bis zum letzten)
MyPocket.DirectionOrientation = 0                       #catRegularOrientation (Reguläre Orientierung)
limit2 = MyPocket.SecondLimit
length1 = limit2.Dimension                              # 2. Begrenzung durch Bemaßung
length1.Value = -25.
CATIA.StartCommand(trans("Update"))

#
#Fasen und Radien
#
MyPart.InWorkObject = MyBody
# 2 identische Fasen über LeerReferenz
EmptyRef = MyPart.CreateReferenceFromName("")                       #Leer-Referenz erzeugen
Chamfer1 = MyPart.ShapeFactory.AddNewChamfer(EmptyRef,0,1,0,2.,45.) #Fase definieren, Parameter s. V5Automation
Pocket = MyPart.MainBody.Shapes.Item("Shaft.1")
Face4 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;4)));None:())"         #Flächen deklarieren, die an Fasenkante liegen
Face5 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;5)));None:())"
Face6 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;6)));None:())"
Endung1 = ";None:(Limits1:();Limits2:()))"                          #Hilfsvar.
Endung2 = ";WithTemporaryBody;WithoutBuildError;WithSelectingFeatureSupport)"   #Hilfsvar.
Edge45 = "Edge:("+ Face4 + ";" + Face5 + Endung1                    #Kante zwischen Flächen 4/5 deklarieren
Edge56 = "Edge:("+ Face5 + ";" + Face6 + Endung1                    #Kante zw. Fl. 5/6
RemEdge45 = "REdge:(" + Edge45 + Endung2                            #RemEdge = Removeable, d.h. Element ist nach OP 
RemEdge56 = "REdge:(" + Edge56 + Endung2                            #                           nicht mehr vorhanden
RRemEdge45 = MyPart.CreateReferenceFromBRepName(RemEdge45, Pocket)  #BRep-Referenz von 1.Kante 
Chamfer1.AddElementToChamfer(RRemEdge45)                            #Zur Auswahl hinzufügen
RRemEdge56 = MyPart.CreateReferenceFromBRepName(RemEdge56, Pocket)  #2.Kante
Chamfer1.AddElementToChamfer(RRemEdge56)
Fase_Nabe=Chamfer1.Length1
Chamfer1.Length1.Rename("Fase_Nabe")                                #Parameter umbenennen

#Fase an Wellenzapfen 1                                             #Einzelne Fase ohne Leer-Referenz
Face7 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;7)));None:())"
Face8 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;8)));None:())"
Edge78 = "Edge:("+ Face7 + ";" + Face8 + Endung1
RemEdge78 = "REdge:(" + Edge78 + Endung2
RRemEdge78 = MyPart.CreateReferenceFromBRepName(RemEdge78, Pocket)
Chamfer78 = MyPart.ShapeFactory.AddNewChamfer(RRemEdge78,0,1,0,2,45)
Fase_Zapfen_1=Chamfer78.Length1
Chamfer78.Length1.Rename("Fase_Zapfen_1")

#Fase an Wellenzapfen 2
Face1 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;1)));None:())"
Face3 = "Face:(Brp:(Shaft.1;0:(Brp:(Sketch.1;3)));None:())"
Edge13 = "Edge:("+ Face1 + ";" + Face3 + Endung1
RemEdge13 = "REdge:(" + Edge13 + Endung2
RRemEdge13 = MyPart.CreateReferenceFromBRepName(RemEdge13, Pocket)
Chamfer13 = MyPart.ShapeFactory.AddNewChamfer(RRemEdge13,0,1,0,2,45)
Fase_Zapfen_2=Chamfer13.Length1
Chamfer13.Length1.Rename("Fase_Zapfen_2")

#InnenRadius Zapfen 1
Edge67 = "Edge:("+ Face6 + ";" + Face7 + Endung1
RemEdge67 = "REdge:(" + Edge67 + Endung2
RRemEdge67 = MyPart.CreateReferenceFromBRepName(RemEdge67, Pocket)
Fillet67 = MyPart.ShapeFactory.AddNewEdgeFilletWithConstantRadius(RRemEdge67,1,1.)
Radius_Zapfen_1=Fillet67.Radius
Fillet67.Radius.Rename("Radius_Zapfen_1")

#InnenRadius Zapfen 2
Edge34 = "Edge:("+ Face3 + ";" + Face4 + Endung1
RemEdge34 = "REdge:(" + Edge34 + Endung2
RRemEdge34 = MyPart.CreateReferenceFromBRepName(RemEdge34, Pocket)
Fillet34 = MyPart.ShapeFactory.AddNewEdgeFilletWithConstantRadius(RRemEdge34,1,1.)
Radius_Zapfen_2=Fillet34.Radius
Fillet34.Radius.Rename("Radius_Zapfen_2")

CATIA.StartCommand(trans("Update"))

#
#Parameter und Beziehungen
#
MyParas = CATIA.ActiveDocument.Part.Parameters
MyRels = MyPart.Relations
#Paras
DNabe = MyParas.CreateDimension ("Durchmesser_Nabe","Length",50.)   #Parameter erzeugen und Wert zuweisen
DNabe.RangeMax = 200
LNabe = MyParas.CreateDimension ("Laenge_Nabe","Length",90.)
LNabe.RangeMax=500                                                  #Parameterbegrenzung MAX
DZapfen1 = MyParas.CreateDimension ("Durchmesser_Zapfen_1","Length",30.)
DZapfen1.RangeMin = 8                                               #Parameterbegrenzung MIN
DZapfen1.RangeMax = 150
LZapfen1 = MyParas.CreateDimension ("Laenge_Zapfen_1","Length",60.)
LZapfen1.RangeMax = 200
DZapfen2 = MyParas.CreateDimension ("Durchmesser_Zapfen_2","Length",36.)
DZapfen2.RangeMin = 8
DZapfen2.RangeMax = 150
LZapfen2 = MyParas.CreateDimension ("Laenge_Zapfen_2","Length",40.)
LZapfen2.RangeMax = 200

#Parameter Konstruktionstabelle
dmin = MyParas.CreateDimension ("dmin","Length",60.)
dmin.Hidden = True                                                  #Parameter verstecken
dmax = MyParas.CreateDimension ("dmax","Length",60.)
dmax.Hidden = True
Nutbreite = MyParas.CreateDimension ("Nutbreite","Length",8.8)
Nutbreite.Hidden = True
Nuttiefe = MyParas.CreateDimension ("Nuttiefe","Length",8.8)
Nuttiefe.Hidden = True
Nutlaenge = MyParas.CreateDimension ("Nutlaenge","Length",40.)
Nutlaenge.Hidden = True

#Relations  , Verknüpfen der Parameter mit Bemaßung
Formel1 = MyRels.CreateFormula("Formel_1","Zapfenlänge 1",DLW2_len,"Laenge_Zapfen_1")
Formel1.Hidden=True                 
Formel2 = MyRels.CreateFormula("Formel_2","Zapfenlänge 2",DLW6_len,"Laenge_Zapfen_2")
Formel2.Hidden=True
Formel3 = MyRels.CreateFormula("Formel_3","Nabennlänge",DLW4_len,"Laenge_Nabe")
Formel3.Hidden=True
Formel4 = MyRels.CreateFormula("Formel_4","Durchmesser Zapfen 1",DLW2_rad,"Durchmesser_Zapfen_1/2.")
Formel4.Hidden=True
Formel5 = MyRels.CreateFormula("Formel_5","Durchmesser Zapfen 1",DLW6_rad,"Durchmesser_Zapfen_2/2.")
Formel5.Hidden=True
Formel6 = MyRels.CreateFormula("Formel_6","Durchmesser Nabe",DLW4_rad,"Durchmesser_Nabe/2.")
Formel6.Hidden=True
#Konstr.Tabelle
Formel7 = MyRels.CreateFormula("Formel_7","Breite Passfedernut",DLP1_LP2,"Nutbreite")
Formel7.Hidden=True
Formel8 = MyRels.CreateFormula("Formel_8","Tiefe Passfedernut",length1,"-Durchmesser_Nabe/2+Nuttiefe")
Formel8.Hidden=True
Formel9 = MyRels.CreateFormula("Formel_9","Länge Passfedernut",DPP1_PP4,"Nutlaenge-Nutbreite")
Formel9.Hidden=True
#Geometrie der Welle
Formel10 = MyRels.CreateFormula("Formel_10","Position Nut mittig auf Nabe",DPP1_AxisV2,
                                "(Laenge_Nabe-Nutlaenge+Nutbreite)/2+Laenge_Zapfen_1")
Formel10.Hidden=True
Formel11 = MyRels.CreateFormula("Formel_11","Fase = 1/20 des Durchmessers",Fase_Zapfen_1,"Durchmesser_Zapfen_1/20.")
Formel11.Hidden=True
Formel12 = MyRels.CreateFormula("Formel_12","Fase = 1/20 des Durchmessers",Fase_Zapfen_2,"Durchmesser_Zapfen_2/20.")
Formel12.Hidden=True
Formel13 = MyRels.CreateFormula("Formel_13","Fase = 1/20 des Durchmessers",Fase_Nabe,"Durchmesser_Nabe/20.")
Formel13.Hidden=True
Formel14 = MyRels.CreateFormula("Formel_14","Radius = Wellenabsatz/2 ",Radius_Zapfen_1,
                                "(Durchmesser_Nabe-(Durchmesser_Zapfen_1+2*Fase_Nabe))/8.")
Formel14.Hidden=True
Formel15 = MyRels.CreateFormula("Formel_15","Radius = Wellenabsatz/2",Radius_Zapfen_2,
                                "(Durchmesser_Nabe-(Durchmesser_Zapfen_2+2*Fase_Nabe))/8.")
Formel15.Hidden=True

#Regeln erzeugen, um Eingabe unsinniger Parameter zu unterbinden
Rule1 = MyRels.CreateProgram("Check Länge Nut-Nabe","", "" +chr(10)+ "if Laenge_Nabe < Nutlaenge+2*Fase_Nabe" +chr(10) + "Message (\"Passfedernut länger als Nabe ! | Mindestlänge Welle (Nabe) = # mm\" , (Nutlaenge+2*Fase_Nabe)*1000)" ) Rule1.Hidden=True Rule2 = MyRels.CreateProgram("Check Durchmesser Zapfen_1-Nabe","", "" +chr(10)+ "if Durchmesser_Zapfen_1 > ( Durchmesser_Nabe-(2*Fase_Nabe+Radius_Zapfen_1+1mm ))" +chr(10) +
"Message (\"Durchmesserverhältnis stimmt nicht!|Entweder Durchmesser_Nabe vergrößern |oder Durchmesser_Zapfen_1 verkleinern\")" )
Rule2.Hidden=True

Rule3 = MyRels.CreateProgram("Check Durchmesser Zapfen_2-Nabe","", "" +chr(10)+
"if Durchmesser_Zapfen_2 > ( Durchmesser_Nabe-(2*Fase_Nabe+Radius_Zapfen_2+1mm ))" +chr(10) +
"Message (\"Durchmesserverhältnis stimmt nicht!|Entweder Durchmesser_Nabe vergrößern |oder Durchmesser_Zapfen_2 verkleinern\")" )
Rule3.Hidden=True

Rule4 = MyRels.CreateProgram("Check Länge Zapfen_1","", "" +chr(10)+
"if Laenge_Zapfen_1 < ( Fase_Zapfen_1+Radius_Zapfen_1+1mm )" +chr(10) +"Message (\"Zapfen_1 zu kurz!\")" )
Rule4.Hidden=True

Rule5 = MyRels.CreateProgram("Check Länge Zapfen_2","", "" +chr(10)+
"if Laenge_Zapfen_2 < ( Fase_Zapfen_2+Radius_Zapfen_2+1mm )" +chr(10) +"Message (\"Zapfen_1 zu kurz!\")" ) Rule5.Hidden=True Rule6 = MyRels.CreateProgram("Check Durchmesser Nabe","", "" +chr(10)+ "if Durchmesser_Nabe > 150mm" +chr(10) +"Message (\"Für D>150mm ist in der Konstruktionstabelle keine Passfedernut nach DIN6885 hinterlegt!\")" )
Rule6.Hidden=True


#Werte Konstruktionstabelle zuweisen
MyTab=MyRels.CreateDesignTable ("Passfeder","Passfedernut nach DIN6885", True, FullPath)    #Pfad zur txt-Datei
MyTab.AddAssociation(dmin, "dmin")                                                      #Zuweisen der Werte an Parameter
MyTab.AddAssociation(dmax, "dmax")
MyTab.AddAssociation (Nutbreite, "breite")                                          
MyTab.AddAssociation (Nuttiefe, "tiefe")
MyTab.AddAssociation(Nutlaenge, "laenge")
MyTab.Configuration=106  

#Check erzeugen, Überprüft ob Größe der Passfedernut zum Durchmesser der Welle passt
check1 = MyRels.CreateCheck("DIN 6885 eingehalten", "", "Durchmesser_Nabe>dmin AND Durchmesser_Nabe<=dmax")
check1.Severity = 1     #1 = Silent, d.h. es wird kein Fenster geöffnet, Anzeige über 'Ampel'

CATIA.StartCommand(trans("Update"))
CATIA.Visible = True    #CATIA wieder einblenden

Print the Volume of a body from CATIA V5

try:
    import win32com.client
except: 
    print "Ooops Pywin32 needed !" 
app=win32com.client.Dispatch('CATIA.Application') 
doc=app.ActiveDocument.Product 
a=doc.Analyze.Volume 
print "The Volume is: ", a

Generating BOM (bill of material) from CATIA V5

To test this sample you should have installed Pywin32 and start CATIA V5 before running this script.

import win32com.client 
catapp = win32com.client.Dispatch("CATIA.Application") 
doc=catapp.ActiveDocument.Product
product_count = doc.Products.Count 
print "This example prints all Parts and subproducts of \
  a CATProduct up to the 2nd level." 
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 a HTML-generated Bill of materialyou should better use the BOM-generation from CATIA V5:
import win32com.client 
catapp = win32com.client.Dispatch("CATIA.Application") 
doc=catapp.ActiveDocument.Product
doc.Product.ExtractBOM(2, "c:\BOM.html")

CATIA V4 and CATPart to VRML Converter

A CATPart to VRML Batchconverter:

The next example uses the \"CATIA V5 Interfaces Object Library\" to
connect to CATIA V5, open a CATPart and export it to VRML. You can do
that with other formats like IGES, STEP, … too (if you have the
licence).

You need Python and Pywin for this example and have also running CATIA V5:

# Demo for converting a CATPart to VRML
# Please start CATIA V5 before running this script

from win32com.client.dynamic import Dispatch
catapp = Dispatch("CATIA.Application")
catapp.Documents.Open("D:\work\Testmodell.CATPart")
catapp.ActiveDocument.ExportData('D:\work\Testmodell.wrl', 'wrl')

A CATIA V4 model to VRML Batchconverter:

You can`t do this interactive in CATIA V5 but with Python. Simply
open a CATIA V4 model and export it to VRML (I did this with R14):

# Demo for converting a CATIA V4 model to VRML
# Please start CATIA V5 before running this script
# Demo for converting a CATIA V4 model to VRML
# Please start CATIA V5 before running this script
from win32com.client.dynamic import Dispatch
catapp = Dispatch("CATIA.Application")
catapp.Documents.Open("D:\work\Testmodell.model")
catapp.ActiveDocument.ExportData('D:\work\Testmodell.wrl', 'wrl')

CATIA V5/DMU Navigator-Programming with Python

Ifyou want to automate CATIA V5 or DMU Navigator with Python you need Pywin32 and Python for Windows or Activestates ActivePython for Windows. Python is free software and you can develop professional applications with all advantages of Python for CATIA V5 or DMU Navigator.

To develop a small application which interacts to CATIA V5 you only have to download your prefered Python Distribution for Windows and can start developing applications for CATIA V5 or DMU Navigator (this 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')
doc=a.ActiveDocument.Product
for i in range(doc.Products.Count):
    print 'Part Number:', doc.Products.Item(i+1).PartNumber

This small example prints out the part names of a loaded CATProduct.

DMU Navigator

If you want to automate DMU Navigator, you can use this dispatch string:

import win32com.client
# Following doesn`t work with CATIA V5 R16 and later
a = win32com.client.Dispatch('DMU.application')

Other examples can be found in the script collection.

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

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 on Microsofts Component Object Model (COM) and Python

More information for developing with Python for COM applications with Pywin32 you can find in this excellent book.

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

How to automate CATIA V5 with Python on Windows

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')
doc=a.ActiveDocument.Product
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.