How to Run script to workbench without manually clicking file => run script?
TAGGED: macros-scripting, scripting-journaling-udf
-
-
September 24, 2021 at 9:54 am
sirusblack07
SubscriberI'm trying to make a python script that opens a saved workbench project and passes a command to workbench. The algorithm is simple as follows;
import os
import time
os.startfile("C:/Users/firas/OneDrive/Bureau/BlankMesher/Ansys_mesher.wbpj") #opens a saved workbench project
workbench_script = "E:/Blank generator/Ansys_mesher/GeoChngWorkbench.py" #the path of the workbench file to run in workbench
RunScript(FilePath="E:/Blank generator/Ansys_mesher/GeoChngWorkbench.py")
The "RunScript" command was obtained when I recorded the manual operation, but when I run python it says "RunScript" not defined because the scope of the action is not well determined and python needs to know that it is applied to Ansys.
Any idea on how to correct this?
Tnx,
September 24, 2021 at 10:34 amErik Kostson
Ansys EmployeeSo from Python you only need to run this I think:
run_line = r'"C:\Program Files\ANSYS Inc\v195\Framework\bin\Win64\runwb2" -B -R D:\sunbatch\test.wbjn'
launch = os.system(run_line)
You need to change in that part where the test.wbjn is defined above to GeoChngWorkbench.wbjn (just change the .py to .wbjn on your file - and the folder D:\..), and use the correct version so change the v195 above to your version (e.g., v212 for 2021 R2).
All the best
Erik
September 24, 2021 at 11:49 amsirusblack07
SubscriberI did exactly what you said:
These are the lines of code:
run_line = r'"D:/ANSYS Inc/v212/Framework/bin/Win64/runwb2" -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbpj'
launch = os.system(run_line)
does this line " -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbjn" mean that I will pass to Ansys the GeoChngWorkbench.wbpj script? In this case why the extension .py is replaced by .wbjn?
I didn't receive any error but nothing happened also.Am I supposed to see workbench open and all the operations happening in the interface or everything will be running underneath the hood? Because I'm expecting some kind of .cdb output files that carry the stiffness data of my model but I don't have an idea on where to find them?
Thank youSeptember 24, 2021 at 12:01 pmErik Kostson
Ansys EmployeeHi
it needs to be .wbjn (so journal file not wbpj wb project file) - so :
run_line = r'"C:\Program Files\ANSYS Inc\v195\Framework\bin\Win64\runwb2" -B -R D:\sunbatch\test.wbjn'
launch = os.system(run_line)
So just change the -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbpj to -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbjn, or -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.py should also work (it id not for me sometimes hence why I issued .wbjn), and it will pass your journal file, so basically what you do manually via WB GUI, and File->Scripting->Run Script FIle (and then we choose the .wbjn or .py file from the file explorer window).
All the best
Erik
September 24, 2021 at 1:14 pmsirusblack07
SubscriberSorry, it still doesn't work, I tried with both .py and .wbjn
When I just run r'"C:\Program Files\ANSYS Inc\v195\Framework\bin\Win64\runwb2"' without the extra bit of code for the script reading, workbench opens fine and I'm able to do the manual execution of the python script without any issues. But when I write the entire command: run_line = r'"D:/ANSYS Inc/v212/Framework/bin/Win64/runwb2" -B -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbjn' I get something similar to the command prompt appearing very briefly and then disappearing and nothing happens.
ThxSeptember 24, 2021 at 1:37 pmErik Kostson
Ansys EmployeeNo worries - that could be something with the .wbjn - try to run it manually from the UI as we said (File->....) and see that it works.
if it does then use this:
run_line = r'"D:/ANSYS Inc/v212/Framework/bin/Win64/runwb2" -I -R E:/Blank generator/Ansys_mesher/GeoChngWorkbench.wbjn
to run it in the interactively (-I) and not in background (-B) where you do not see any errors.
But in theory that should work as I have used here today (my wbjn or py is fine though).
hope that helps
all the best
Erik
September 24, 2021 at 5:31 pmsirusblack07
SubscriberI finally managed to make it work after several attempts ... all I needed to do is remove the space in the folder name "Blank generator", as it was preventing the command from working.
It works fine with both -I or -B.
I appreciate the time you dedicated to my issue. Thank you!
Viewing 6 reply threads- The topic ‘How to Run script to workbench without manually clicking file => run script?’ is closed to new replies.
Ansys Innovation SpaceTrending discussionsTop Contributors-
1992
-
896
-
599
-
591
-
418
Top Rated Tags© 2025 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-