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?
You can do this by using the --script-args option. Here is an examplary batch call to optiSLang:
--script-args
"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
--python create_workflow.py
create_workflow.py
--script-args 111 222.2 "333"
111
222.2
"333"
--new optiSLang-project.opf
optiSLang-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 by sys.args[2] and so on. Two remarks: 1) The first item in the sys.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.
sys.args[1]
sys.args[2]
sys.argv