0

I have been working on a code to run a .CATScript of CATIA v5 from python 3.6. In short, the objective is to run the .CATScript from python module. By running the following script from python console, the CATIA interface opens but the script is not running. The GUI of CATIA which opens is for a new product but not for the script. Could someone please help me with this problem?

The python code looks as

import os;
import sys;
import shutil;
import win32com.client




os.startfile("C:/FK-Programme/Dassault Systemes/B24/win_b64/code/bin/CNEXT.exe")  

os.system("D:\Macro_python\Macro_cylinder.CATScript")

print ("Normal Termination")

whereas the .CATScript looks like

Sub CATMain()

CATIA.DisplayFileAlerts = False

Dim FileToOpen as String
Dim partDocument1 As Document
Dim part1 As Part
Dim LengthPara As Parameter
Dim parameters1 As Parameters
Dim RadiusPara As Parameter

FileToOpen = "D:\Macro_python\Cylinder.CATPart"

Set partDocument1 = CATIA.Documents.Open(FileToOpen)

Set part1 = partDocument1.Part

Set parameters1 = part1.Parameters

Set LengthPara = parameters1.RootParameterSet.DirectParameters.Item("Length")

LengthPara.Value = 50

Set RadiusPara = parameters1.RootParameterSet.DirectParameters.Item("Radius")

RadiusPara.Value = 10

partDocument1.Part.Update

partDocument1.ExportData "D:\Macro_python\Cylinder.CATPart\cylinder.stp", "stp" 

End Sub

Any help will be greatly appreciated.

Thank you

  • CNEXT.exe needs an argument with the macro to run. Something like `CNEXT.exe -batch -macro {full path to CATScript macro}` – gdir Apr 16 '18 at 14:32
  • Thank you very much for your suggestion. In this case where the CATIA GUI and the macro open not at the same time but consecutively, I am not sure how do I realise this function in the macro. Normally from the command line, I start the script the same way you mentioned. But if I use python to call catia and run a script, I don't know where I should include the options -batch and .macro. Could you please provide me any suggestion or help to handle it? thank you – Simulationeng_sam Apr 17 '18 at 15:36
  • Could someone please help me with this problem here? Thank you – Simulationeng_sam Apr 18 '18 at 04:48
  • I don't use Python myself, but this looks like solution to your problem: https://stackoverflow.com/questions/26680647/pass-arguments-to-executable-in-python – gdir Apr 18 '18 at 04:53
  • Yes. Thank you. I will check the contents under the link now. – Simulationeng_sam Apr 18 '18 at 05:27

0 Answers0