How to pass arguments to optiSLang executed in batch mode


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?


Best Answer

  • Georg Kandler
    Georg Kandler Member, Employee Posts: 8
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Name Dropper
    edited May 17 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 --script-args 111 222.2 "333" --new optiSLang-project.opf

    Some explanation:

    • -b triggers the batch mode.
    • --python initiates the python script
    • --script-args 111 222.2 "333" is used to define three arguments with values 111, 222.2 and "333"
    • --new optiSLang-project.opf saves the project under optiSLang-project.opf

    Inside the script, the arguments can be accessed like so:

    import sys
    args = sys.argv

    The resulting print output will look like this:

    ['', '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.