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


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.