.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic/01-connect.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_00-basic_01-connect.py: .. _ref_connect: Connect services ================ This example shows how to start an Ansys Dynamic Reporting service via a Docker image, create a second instance of the ``Service`` class, and connect it to the already running service. It then shows how to create and modify items in the original database with this new instance. .. note:: This example assumes that you do not have a local Ansys installation but are starting an Ansys Dynamic Reporting Service via a Docker image on a new database. .. GENERATED FROM PYTHON SOURCE LINES 21-26 Start an Ansys Dynamic Reporting service ---------------------------------------- Start an Ansys Dynamic Reporting service via a Docker image on a new database. The path for the database directory must be to an empty directory. .. GENERATED FROM PYTHON SOURCE LINES 26-33 .. code-block:: default import ansys.dynamicreporting.core as adr db_dir = r"C:\tmp\new_database" adr_service = adr.Service(ansys_installation="docker", db_directory=db_dir) session_guid = adr_service.start(create_db=True) .. GENERATED FROM PYTHON SOURCE LINES 34-41 Create items ------------ Given that the Ansys Dynamic Reporting service is running on top of an empty database, create a few items in the database and then visualize the default report that shows all these items, one after the other. Note that this code assumes that you have files on disk for the payload of the items. .. GENERATED FROM PYTHON SOURCE LINES 41-50 .. code-block:: default my_text = adr_service.create_item(obj_name="Text", source="Documentation") my_text.item_text = "This is a simple string with no HTML formatting." my_animation = adr_service.create_item(obj_name="Animation File", source="Documentation") my_animation.item_animation = r"D:\tmp\myanim.mp4" my_file = adr_service.create_item(obj_name="General File", source="Documentation") my_file.item_file = r"D:\tmp\anytfile.txt" adr_service.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 51-59 .. image:: /_static/01_connect_0.png Create another connected instance --------------------------------- Now that you have a running Ansys Dynamic Reporting service, create a second instance of the ``Reporting`` class and use it to connect to the database. Visualize the default report. .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: default connected_s = adr.Service() connected_s.connect(url=adr_service.url) connected_s.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 67-75 .. image:: /_static/01_connect_1.png Create an item via the connected object --------------------------------------- Use the new object for the connected service to create an ``Image`` item. Visualize the default report again to verify that this item has been added to the database. .. GENERATED FROM PYTHON SOURCE LINES 76-82 .. code-block:: default my_image = connected_s.create_item(obj_name="Image", source="Documentation") my_image.item_image = r"D:\tmp\local_img.png" connected_s.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 83-93 .. image:: /_static/01_connect_3.png Visualize only items from a session ----------------------------------- Assume that you want to visualize only the items that were created from the connected Ansys Dynamic Reporting session and not the original instance. To achieve this, you add a filter to the default report visualization. Note that running this method on either of the Ansys Dynamic Reporting instances produces the same result. .. GENERATED FROM PYTHON SOURCE LINES 94-97 .. code-block:: default adr_service.visualize_report(filter=f"A|s_guid|cont|{connected_s.session_guid}") .. GENERATED FROM PYTHON SOURCE LINES 98-103 Close the service ----------------- Close the Ansys Dynamic Reporting service. The database with the items that were created remains on disk. .. GENERATED FROM PYTHON SOURCE LINES 103-106 .. code-block:: default # sphinx_gallery_thumbnail_path = '_static/01_connect_3.png' adr_service.stop() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_examples_00-basic_01-connect.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-connect.py <01-connect.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-connect.ipynb <01-connect.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_