.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic/02-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_02-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-34 .. code-block:: Python import ansys.dynamicreporting.core as adr import ansys.dynamicreporting.core.examples as examples 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 35-42 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 42-51 .. code-block:: Python 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 = examples.download_file("dam_break.mp4", "input_data") my_file = adr_service.create_item(obj_name="General File", source="Documentation") my_file.item_file = examples.download_file("report_template.json", "multi_physics") adr_service.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 52-62 .. image:: /_static/01_connect_0.png .. _ref_connect_to_a_running_service: Create another connected instance --------------------------------- Now that you have a running Ansys Dynamic Reporting service, create a second instance of the ``Service`` class and use it to connect to the database. Visualize the default report. .. GENERATED FROM PYTHON SOURCE LINES 63-69 .. code-block:: Python connected_s = adr.Service() connected_s.connect(url=adr_service.url) connected_s.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 70-78 .. 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 79-85 .. code-block:: Python my_image = connected_s.create_item(obj_name="Image", source="Documentation") my_image.item_image = examples.download_file("introduction.png", "multi_physics") connected_s.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 86-96 .. 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 97-100 .. code-block:: Python adr_service.visualize_report(item_filter=f"A|s_guid|cont|{connected_s.session_guid}") .. GENERATED FROM PYTHON SOURCE LINES 101-106 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 106-109 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/01_connect_3.png' adr_service.stop() .. _sphx_glr_download_examples_00-basic_02-connect.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02-connect.ipynb <02-connect.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02-connect.py <02-connect.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02-connect.zip <02-connect.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_