How to pass arguments to optiSLang executed in batch mode
Georg Kandler
Member, Employee Posts: 8
✭✭✭
I want to execute optiSLang in batch mode and control the workflow creation by a python script. How can I pass arguments to the python script?
Tagged:
0
Best Answer
-
You can do this by using the
--script-args
option. Here is an examplary batch call to optiSLang:"C:\Program Files\ANSYS Inc\v241\optiSLang\optislang.exe" -b --python create_workflow.py --script-args 111 222.2 "333" --new optiSLang-project.opf
Some explanation:
-b
triggers the batch mode.--python create_workflow.py
initiates the python scriptcreate_workflow.py
--script-args 111 222.2 "333"
is used to define three arguments with values111
,222.2
and"333"
--new optiSLang-project.opf
saves the project underoptiSLang-project.opf
Inside the
create_workflow.py
script, the arguments can be accessed like so:import sys args = sys.argv print(str(args))
The resulting print output will look like this:
['create_workflow.py', '111', '222.2', '333']
So you can access the first argument by using
sys.args[1]
, the second bysys.args[2]
and so on.
Two remarks:
1) The first item in thesys.argv
list is the name of the python script itself.
2) All items in the list are of type string. Don't forget to convert the arguments from string to the appropriate data type in your python script.0