Basic usage#

To start a project, you use the start method. This code starts the project for the Simple calculator example:

from pathlib import Path
from ansys.optislang.core import Optislang, examples

osl = Optislang()
path_to_file = examples.get_files("simple_calculator")[0]

To save the project, use the save(), save_as(), or save_copy() method. This code uses the save_as() method:

project_path = Path().cwd() / "test_project.opf"

If an optiSLang instance is created with the default parameters, the optiSLang project is located in a temporary directory. Therefore, to preserve the project permanently, you should use either the save_as() or save_copy() method.

To create a project or open an existing one, you use the new() or open() method. This code creates a project:

new_project = Path().cwd() / "new_project.opf"

To obtain some general information about a project, run this code:


Or, you can run specific requests like shown in this code:

print(f"Version: {osl.get_osl_version_string()}")
print(f"Working directory: {osl.get_working_dir()}")

When you no longer need to use the Optislang() instance, close the connection with the optiSLang server by running this code: