I would like to use my macro (.CATScript) to open the catia interface and make the changes listed in the macro script to the .CATpart and give output as .stp file. Is it possible to use python to realise this function?
There was an example in Run a Catia macro with a python script, but it didn't work in my case. I edited the code as below and gave it a run.
import win32com.client catapp = win32com.client.Dispatch("CATIA.Application") catapp.StartCommand('Macro_schweller_model_lsopt.CATScript')
The error I had was
File "C:\FK-Programme\python36-32\Anaconda\Install\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Ungültige Klassenzeichenfolge', None, None)
My .CATscript looks like this
Sub CATMain() Dim FileToOpen as String Dim partDocument1 As Document Dim part1 As Part Dim AnglePara As Parameter Dim parameters1 As Parameters Dim AmplitudePara As Parameter Dim WavelengthPara As Parameter FileToOpen = "E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1\Schweller_fully_corrugated.CATPart" Set partDocument1 = CATIA.Documents.Open(FileToOpen) Set part1 = partDocument1.Part Set parameters1 = part1.Parameters Set AnglePara = parameters1.RootParameterSet.DirectParameters.Item("Angle") AnglePara.Value = -7 Set AmplitudePara = parameters1.RootParameterSet.DirectParameters.Item("Amplitude") AmplitudePara.Value = 30 Set WavelengthPara = parameters1.RootParameterSet.DirectParameters.Item("Wavelength") WavelengthPara.Value = 30 CATIA.DisplayFileAlerts = False partDocument1.Part.Update partDocument1.ExportData "E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1\Schweller.stp", "stp" End Sub