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]
osl.run_python_file(file_path=path_to_file)
osl.start()
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"
osl.save_as(project_path)
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"
osl.new()
osl.save_as(new_project)
To obtain some general information about a project, run this code:
print(osl)
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:
osl.dispose()