Package: ansys-optislang-core
OverviewPyOptiSLang is a Python wrapper for Ansys optiSLang. It supports Pythonic
access to Ansys optiSLang to be able to communicate with Ansys optiSLang directly from Python.
The latestansys-optislangpackage provides these capabilities:Starting and managing local instances of Ansys optiSLangRemote connections to Ansys optiSLang instances via TCP/IPCreate new Ansys optiSLang projectOpen existing Ansys optiSLang projectControl Ansys optiSLang project executionSave Ansys optiSLang projectExecute classic Ansys optiSLang Python API script on backend sideEvaluate designs on root project levelDocumentation and issuesFor comprehensive information on PyOptiSLang, see the latest releasedocumentation. On thePyOptiSLang Issuespage,
you can create issues to submit questions, report bugs, and request new features.
This is the best place to post questions and code.InstallationTheansys-optislang-corepackage supports Python 3.7 through 3.11 on
Windows and Linux. Three modes of installation are available:User installationDeveloper installationOffline installationFor either a developer or offline installation, consider using avirtual environment.User installationInstall the latest release fromPyPiwith this command:pip install ansys-optislang-coreAlternatively, install the latestPyOptiSLang GitHubpackage with this command:pip install git+https://github.com/ansys/pyoptislang.gitDeveloper installationIf you plan on doing localdevelopmentwith GitHub, clone and
install PyOptiSLang with this code:git clone https://github.com/ansys/pyoptislang.git
cd pyoptislang
pip install -e .A developer installation allows you to editansys-optislang-corefiles locally. Any changes that you make are reflected in your setup
after restarting the Python kernel.Offline installationUsing a wheelhouse can be helpful if you work for a company that restricts access to
external networks. From theReleasespage in the PyOptiSLang repository, you can find the wheelhouses for a particular release in its
assets and download the wheelhouse corresponding to your setup.You can then install PyOptiSLang and all of its dependencies from one single entry point
that can be shared internally, which eases the security review of the PyOptiSLang package content.For example, on Linux with Python 3.7, unzip the wheelhouse and install PyOptiSLang with code
like this:unzipPyOptiSLang-v0.1.0-wheelhouse-Linux-3.7.zipwheelhousepipinstallansys-optislang-core-fwheelhouse--no-index--upgrade--ignore-installedIf you’re on Windows with Python 3.9, unzip the wheelhouse to a wheelhouse directory and
then install using the samepipcommand as in the preceding Linux code example.DependenciesYou must have a local licensed copy or a remote instance of optiSLang installed. The first
supported version is 2023 R1.Getting startedUsing theOptislangclass, you can either launch optiSLang locally or connect to a
remote optiSLang instance.Launch optiSLang locallyFor launching optiSLang locally, both thehostandportparameters in theOptislangclass must be set toNone, which are their defaults. Other parameters can optionally
be specified.fromansys.optislang.coreimportOptislangosl=Optislang()osl.dispose()Connect to a remote optiSLang instanceFor remote connection, it is assumed that an optiSLang instance is already running on
a remote (or local) host as a server. In this case, you must specify thehostandportparameters. Parameters related to the execution of a new optiSLang instance are ignored.fromansys.optislang.coreimportOptislanghost="127.0.0.1"port=5310osl=Optislang(host=host,port=port)osl.dispose()Basic usageThis code shows how to launch optiSLang locally, open and run a Python
script file, save the results to a new project, and then close the
connection:fromansys.optislang.coreimportOptislangosl=Optislang()file_path=r"C:\Users\Username\my_scripts\myscript.py"osl.application.project.run_python_file(path=file_path)osl.application.save_copy("MyNewProject.opf")osl.dispose()License and acknowledgmentsPyOptiSLang is licensed under the MIT license.PyOptiSLang makes no commercial claim over Ansys whatsoever. This library extends the
functionality of Ansys optiSLang by adding a Python interface to optiSLang without
changing the core behavior or license of the original software. The use of the interactive control
of PyOptiSLang requires a legally licensed local copy of optiSLang.For more information on optiSLang, see theAnsys optiSLangpage on the Ansys website.