.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/osl_server/01_basic_queries.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_osl_server_01_basic_queries.py: .. _ref_osl_server_basic_queries: Basic server queries -------------------- This example demonstrates how to use PyOptiSLang to perform basic queries/commands on the optiSLang server using the explicit API. .. GENERATED FROM PYTHON SOURCE LINES 35-38 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform the required imports. .. GENERATED FROM PYTHON SOURCE LINES 38-49 .. code-block:: Python from pathlib import Path import tempfile from typing import TYPE_CHECKING from ansys.optislang.core import Optislang import ansys.optislang.core.examples as examples if TYPE_CHECKING: from ansys.optislang.core.tcp.osl_server import TcpOslServer .. GENERATED FROM PYTHON SOURCE LINES 50-53 Create optiSLang instance ~~~~~~~~~~~~~~~~~~~~~~~~~ Create the optiSLang instance. .. GENERATED FROM PYTHON SOURCE LINES 53-62 .. code-block:: Python example_path = examples.get_files("ten_bar_truss")[1][0] tmp_dir = Path(tempfile.mkdtemp()) file_path = tmp_dir / "evaluate_design_example.opf" osl = Optislang(project_path=example_path, ini_timeout=60) osl.application.save_as(file_path) osl_server: TcpOslServer = osl.osl_server .. GENERATED FROM PYTHON SOURCE LINES 63-66 Get optiSLang server connection info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Print osl server host and port. .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: Python print(f"Server host/address: {osl_server.host}") print(f"Server port: {osl_server.port}") .. GENERATED FROM PYTHON SOURCE LINES 70-73 Get optiSLang info and optiSLang server info ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Print optiSLang and optiSLang server info. .. GENERATED FROM PYTHON SOURCE LINES 73-75 .. code-block:: Python print(f"Server info: {osl_server.get_server_info()}") .. GENERATED FROM PYTHON SOURCE LINES 76-79 Get basic project info ~~~~~~~~~~~~~~~~~~~~~~ Query basic server/project info. .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. code-block:: Python print(f"Basic project info: {osl_server.get_basic_project_info()}") print(f"Full project tree: {osl_server.get_full_project_tree()}") .. GENERATED FROM PYTHON SOURCE LINES 84-87 Stop and cancel project ~~~~~~~~~~~~~~~~~~~~~~~ Stop and cancel the project. .. GENERATED FROM PYTHON SOURCE LINES 87-89 .. code-block:: Python osl.dispose() .. _sphx_glr_download_examples_osl_server_01_basic_queries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_basic_queries.ipynb <01_basic_queries.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_basic_queries.py <01_basic_queries.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_