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?

Tagged:

Best Answer

  • Georg Kandler
    Georg Kandler Member, Employee Posts: 8
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Name Dropper
    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 script create_workflow.py
    • --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 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.