Autor
|
Thema: How to add syntax Normal Termination to the existing .CATScript? (1182 mal gelesen)
|
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 14. Apr. 2018 08:45 <-- editieren / zitieren --> Unities abgeben:
Hello all, I would like to run a parametric CATIA model using .CATScript. It will then be coupled with LS-OPT. So in order to comply with the LS-Opt specification, the script for CATIA (here .CATScript) is supposed to have a syntax "normal termination" which would mean after running the script every time, it should print "normal termination". Could someone please help me how to add this function to the existing .CATScript? Thank you very much.
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 14. Apr. 2018 18:04 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
|
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 14. Apr. 2018 21:54 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, Thank you very much for your reply. I start CATScript from the command line as follows "Directory where CNEXT.exe is located" -batch -macro "directory where the .CATScript is located" When its run from the windows command line, it works perfectly fine. However, I would want to add the function to the end of the script where it says "print normal termination". In reality while using with LS-Opt, it should work only when the .CATScript is able to say that the function has terminated normally. Could you please help me with this? thank you
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 14. Apr. 2018 22:24 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi IMHO it is not possible to get a reply from the script if it's started in this way. As a workaround you could write a log file (or even create a file) which will be read/checked in your LS-Opt script. Or: get your COM-interface between Python and Catia working, so you could transfer the CATScript code to your python script. Regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 09:02 <-- editieren / zitieren --> Unities abgeben:
|
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 15:19 <-- editieren / zitieren --> Unities abgeben:
Hello, I tried compiling a code to use with python. The objective is to call CATIA from Pythin and run the script. By running this script, i could see new CATIA GUI opening but the script wont run. The window opens for Product1 and it wont progress after this stage. The python code looks like Code: 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 ' N o r m a l t e r m i n a t i o n'
whereas the .CATScript looks like
Code: 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
Am i missing any syntax which would support the code accomplish its function? Could someone please help me with this? Thank you very much
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 15. Apr. 2018 15:24 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi My idea was to use the COM-Interface like win32com.client.Dispatch("CATIA.Application"). Does this work on your PC? If not maybe you should use a workaround (log file, ...) Regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 15:53 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, Using win32 doesnt work on my PC. It says dispatch error. When i used the script(as mentioned in the previous thread), it atleast starts the application. regarding this option log.file, could you please explain it a little about it? or please tell me where i could find relevant information about it? From one of the questions posted regarding it in this forum, i activated the properties to write a log.file using tools ==> options==>general ==> statistics. is this approach correct? thank you Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 15. Apr. 2018 16:04 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi My idea is to create a file within the CATScript (see CreateFile in the V5Automation.chm) In your python script you can check if the file exist (and delete it to prepare for the next run). Does os.startfile (or however you start the CATScript) wait for end of the catia script? Otherwise it wont work. Regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 16:28 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, Thank you very much for your reply. regarding the python script, It runs until os.startfile(directory of CNEXT.exe) and the next line i have os.system(directory for the .CATScript) where the code stops and wont proceed after that point. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 16:46 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, there is no way to add the syntax "print normal termination" directly in the CATScript? I would just want the script to write that the process was terminated "normal" everytime it is evoked. Is it possible to have such syntax in vbs script type? Thank you. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 15. Apr. 2018 17:13 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi Why don't you execute the macro with the parameter -macro in the command line? Where do wanna have the message "normal termination"? Have you tried a (VBA) MsgBox? Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 17:39 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, 1. I only want start it from the command line since thats the only way to use CATIA as user defined solver with LS-OPt. In LS-Opt, basically there are two locations. One is for the command line and the other is for input file. I approached this by giving the directory of CNEXT.exe in the command line so (per ls opt manual), its for any executable to start a solver. then in the input file space, i added a file called "CATIA.bat" which consists of Code: -batch -macro "directory of the .CATScript"
. The job that runs in the background is that LS-Opt will execute the solver mentioned in the command line and run the input file ( mentioned in the "Input" column). 2. I would want the script to print "normal termination" at the end of running the macro .CATScript.Hence i would prefer to add the syntax to realise the funxtion in the .CATScript if possible. 3. I havent tried using MsgBox yet. I am hestitating beacuse i dont think it will work harmoniously with LS-Opt. Could you please suggest me if its possible to convert the contents from .CATscript format to vbs format if its possible to include such syntax(print normal termination")? Thank you very much Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 15. Apr. 2018 20:21 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi Where do you need the "print normal termination"? Here a short example to using Catia with vbs: Code: Dim CATIA Dim PartDocSet CATIA = CreateObject("CATIA.Application") 'or GetObject to get a running Session CATIA.DisplayFileAlerts = False Set PartDoc=CATIA.Documents.Add("Part") PartDoc.SaveAs("D:\BlaBla.CATPart") PartDoc.Close CATIA.Quit
I'am wondering: first Python, then CATScript and .bat and now vbs Regards, Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 15. Apr. 2018 21:14 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, Thank you very much for your suggestion. I am sorry that i confused you. okay. i will try to explain it correctly this time. I have an example file where a vbs script was called by python. The script reads which parameters to change in the model by running the VBS script and give out .igs file which will be then meshed by Hypermesh. The script looks like (created with Python 2.6) Code: #============================================================================== # Import modules #============================================================================== # import os; import shutil; from datetime import date; import sys; import time; # ## actualPath = os.getcwd() # executableProgramDisc = 'C:\\' #executableOptimizationDisc = 'D:\\' executableOptimizationDisc = 'E:\\' # #executableCatiaPath = 'FK-Programme\\Dassault Systemes\\B24\\win_b64\\code\\bin\\' executableCatiaPath = 'FK-Programme\\Catia\\B24\\win_b64\\code\\bin\\' executableCatiaName = 'CNEXT.exe' # # executableCatiaVBS = 'cylinder.catvbs' # executableIGSModel = 'cylinder.igs' # # executableBatchmeshConfig = 'Config.cfg' # executableKEYFile = 'dyna.key' # # #============================================================================== # Ausführen des catvb-Scriptes und Export des IGS-Files #============================================================================== # import win32com.client catapp = win32com.client.Dispatch('CATIA.Application') os.system(executableCatiaVBS) # #============================================================================== # Erzeugung Config-File Batchmesh #============================================================================== # a0='<?xml version="1.0" encoding="UTF-8"?>\n' a1='<BatchMeshConfiguration Author="xxx" Date_saved="Thu Jan 19 11:03:49 CET 2017">\n' a2=' <!--Auto Generated.Please do not edit-->\n' a3=' <UserProcedure PRE_GEOMETRY_LOAD="" PRE_BATCHMESH="" POST_BATCHMESH="" PRE_RUN="" POST_RUN="">\n' a4=' <Procedure Alias="opistruct_mesh" TclFileName="C:/FK-Programme/Altair/14.0/hm/batchmesh/OptistructOutput.tcl" EntryProcName="optistructexport" ProcParams="" />\n' a5=' <Procedure Alias="opistruct_mesh_rename" TclFileName="C:/FK-Programme/Altair/14.0/hm/batchmesh/OptistructOutputWithNewName.tcl" EntryProcName="optistructexport" ProcParams="" />\n' a6=' <Procedure Alias="nastran_mesh" TclFileName="C:/FK-Programme/Altair/14.0/hm/batchmesh/NastranOutput.tcl" EntryProcName="nastranexport" ProcParams="" />\n' a7=' <Procedure Alias="nastran_mesh_rename" TclFileName="C:/FK-Programme/Altair/14.0/hm/batchmesh/NastranOutputWithNewName.tcl" EntryProcName="nastranexport" ProcParams="" />\n' a9=' <Procedure Alias="dyna" TclFileName="C:/FK-Programme/Altair/14.0/hm/batchmesh/DynaOutput.tcl" EntryProcName="dyna971export" ProcParams="" />\n' a10=' </UserProcedure>\n' a11=' <ModelTypeDefinition Default_CADType="IGES">\n' a12=' <ModelType CADType="ACIS" hm_name="acis" ModelExt="*.sat " InputParameters="" />\n' a13=' <ModelType CADType="Auto" hm_name="Detect" ModelExt="*.* " InputParameters="" />\n' a14=' <ModelType CADType="CATIA" hm_name="catia" ModelExt="*.model *.dat *.CATPart *.CATProduct *.cgr " InputParameters="" />\n' a15=' <ModelType CADType="CT-Parasolid" hm_name="ct-parasolid" ModelExt="*.x_t *.x_b *.xmt_txt " InputParameters="" />\n' a16=' <ModelType CADType="CT-UG" hm_name="ct-ug" ModelExt="*.prt *.part " InputParameters="" />\n' a17=' <ModelType CADType="DXF" hm_name="dxf" ModelExt="*.dxf " InputParameters="" />\n' a18=' <ModelType CADType="HyperMesh" hm_name="hm" ModelExt="*.hm* " InputParameters="" />\n' a19=' <ModelType CADType="IGES" hm_name="iges" ModelExt="*.igs *.iges " InputParameters="" />\n' a20=' <ModelType CADType="Intergraph" hm_name="intergraph" ModelExt="*.xml " InputParameters="" />\n' a21=' <ModelType CADType="JT" hm_name="jt" ModelExt="*.jt " InputParameters="" />\n' a22=' <ModelType CADType="PDGS" hm_name="pdgs" ModelExt="*.fsf " InputParameters="" />\n' a23=' <ModelType CADType="Parasolid" hm_name="parasolid-parasolid" ModelExt="*.x_t *.x_b *.xmt_txt " InputParameters="" />\n' a24=' <ModelType CADType="Pro E" hm_name="proe" ModelExt="*.prt* *.asm* " InputParameters="" />\n' a25=' <ModelType CADType="STEP" hm_name="step" ModelExt="*.step *.stp " InputParameters="" />\n' a26=' <ModelType CADType="SolidWorks" hm_name="solidworks" ModelExt="*.sldprt* *.sldasm* " InputParameters="" />\n' a27=' <ModelType CADType="Tribon" hm_name="tribon" ModelExt="*.xml " InputParameters="" />\n' a28=' <ModelType CADType="UG" hm_name="ug" ModelExt="*.prt *.part " InputParameters="" />\n' a29=' <ModelType CADType="VDAFS" hm_name="vdafs" ModelExt="*.vda *.vdafs " InputParameters="" />\n' a30=' </ModelTypeDefinition>\n' a31=' <ExecuteParams ModelSourceDir="' + executableOptimizationDisc + executableOptimizationPath + '" ResultDir="' + executableOptimizationDisc + executableOptimizationPath + '" />\n' a32=' <MeshTypeDefinition>\n' a34=' <MeshType MeshTypeAlias="8mm user" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/8mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/8mm.user.param" />\n' a35=' <MeshType MeshTypeAlias="10mm auto" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/10mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/10mm.auto.param" />\n' a36=' <MeshType MeshTypeAlias="10mm user" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/10mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/10mm.user.param" />\n' a37=' <MeshType MeshTypeAlias="12mm auto" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/12mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/12mm.auto.param" />\n' a38=' <MeshType MeshTypeAlias="12mm user" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/12mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/12mm.user.param" />\n' a39=' <MeshType MeshTypeAlias="15mm auto" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/15mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/15mm.auto.param" />\n' a40=' <MeshType MeshTypeAlias="20mm auto" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/20mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/20mm.auto.param" />\n' a41=' <MeshType MeshTypeAlias="8mm auto" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/8mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/8mm.auto.param" />\n' a42=' <MeshType MeshTypeAlias="crash_2mm" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_2mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_2mm.param" />\n' a43=' <MeshType MeshTypeAlias="crash_4mm" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_4mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_4mm.param" />\n' a44=' <MeshType MeshTypeAlias="crash_5mm" CriteriaFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_5mm.criteria" ParametersFile="C:/FK-Programme/Altair/14.0/hm/batchmesh/crash_5mm.param" />\n' a45=' </MeshTypeDefinition>\n' a46=' <Multi_CPU Number_of_CPU="auto" />\n' a47=' <BatchMeshPane Recursive="No" Relocate="No" />\n' a48=' <ModelList Enable="Yes" AutoStop="No">\n' a49=' <Model Name="' + executableOptimizationDisc + executableOptimizationPath + executableIGSModel + '" Type="IGES" MeshType="crash_4mm" PreGeomTCL="" PreMeshTCL="" PosMeshTCL="dyna" />\n' a50=' </ModelList>\n' a51='</BatchMeshConfiguration>\n' # Configfile = [a0, a1, a2, a3, a4, a5, a6, a7, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51] # v = file(executableOptimizationDisc + executableOptimizationPath + executableBatchmeshConfig, 'w') for o in Configfile: v.write(o) v.close() # # #============================================================================== # Ausführen von Batchmesh und Export von KEY-File #============================================================================== # sys.stdout.flush() time.sleep(2.0) # executableBatchmeshCommand_draft = os.path.join(executableProgramDisc, executableBatchmeshPath, executableBatchmeshName) executableBatchmeshCommand = '"'+executableBatchmeshCommand_draft+'"' # # #Options to start Batchmesh config = ' -config_file ' + executableOptimizationDisc + executableOptimizationPath + executableBatchmeshConfig modus = ' -batch' # batchmeshteil1 = 'bm_' batchmeshnumber = '_001' # batchmeshordner = (batchmeshteil1 + today + batchmeshnumber) # batchmeshStartOption = config + modus # os.system(executableBatchmeshCommand + batchmeshStartOption) # # sys.stdout.flush() time.sleep(0.9) # # #=============================================================================== # key-File (+IGS-Dateien) kopieren in ein neues Verzeichnis #=============================================================================== # shutil.copy2(executableOptimizationDisc + executableOptimizationPath + batchmeshordner+ '\\' + executableKEYFile, actualPath + '\\' + executableKEYFile) ## print 'N o r m a l t e r m i n a t i o n'
So, from this calling vbs script using win32 didnt work. hence i replaced it with command os.startfile. I apologize for writinh down the whole script. I did only to make sure i explained the issue properly this time. Thank you Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
bgrittmann Moderator Konstrukteur
Beiträge: 11780 Registriert: 30.11.2006 CATIA V5R19
|
erstellt am: 16. Apr. 2018 08:22 <-- editieren / zitieren --> Unities abgeben: Nur für Sam2021
Hi Does your example work? Your example starts a .CATvbs and not a .vbs. Main difference between CATScript and CATvbs: in CATvbs the lines with Dim are not allowed. Does my .vbs example work? Bernd ------------------ Warum einfach, wenn es auch kompliziert geht. Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |
Sam2021 Mitglied Student
Beiträge: 30 Registriert: 26.03.2018
|
erstellt am: 16. Apr. 2018 08:56 <-- editieren / zitieren --> Unities abgeben:
Dear Bernd, Thank you very much for your response. 1. The example file didn't work the same way it was. It showed some dispatch error while starting CATIA which then referenced to "dynamic.py". So I replaced import win32com.client with os.startfile ("directory where CNEXT.exe is located"). After the change, I was able to start CATIA from python but couldn't run the script. 2. My bad. I misunderstood. I thought catvbs is same as vbs script. Now considering LS-OPT is the client and CATIA is the server, and if LS-Opt wants to change the parameters in the CAD model and request the geometry output as .stp, which of the programming languages should I prefer? I read on the internet where people say .catvbs is preferred over .catscript. Could you please offer me some tutorials how to realise this task in a .CATVbs script? Thank you very much Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP |