.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic/00-create_db.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_00-create_db.py: .. _ref_createdb: Create a database ================= This example shows how to use PyDynamicReporting to create an Ansys Dynamic Reporting service, create a database for this service, and create items in this database. .. note:: This example assumes that you have a local Ansys installation. .. GENERATED FROM PYTHON SOURCE LINES 17-21 Start an Ansys Dynamic Reporting service ---------------------------------------- Start an Ansys Dynamic Reporting service with a new database. The path for the database directory must be to an empty directory. .. GENERATED FROM PYTHON SOURCE LINES 21-31 .. code-block:: default import numpy as np import ansys.dynamicreporting.core as adr ansys_loc = r"C:\Program Files\ANSYS Inc\v232" db_dir = r"C:\tmp\new_database" adr_service = adr.Service(ansys_installation=ansys_loc, db_directory=db_dir) session_guid = adr_service.start(create_db=True) .. GENERATED FROM PYTHON SOURCE LINES 32-38 Create items ------------ Now that an Ansys Dynamic Reporting service is running on top of the new database, create some items of different types (text, image, and 3D scene) in the database. The payload for these items comes from files on disk. .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. code-block:: default my_text = adr_service.create_item() my_text.item_text = "

Analysis Title

This is the first of many items" my_image = adr_service.create_item() my_image.item_image = r"""D:\tmp\tmp_img.png""" my_scene = adr_service.create_item() my_scene.item_scene = r"""D:\tmp\tmp_scene.avz""" .. GENERATED FROM PYTHON SOURCE LINES 47-55 Visualize all items ------------------- Visualize all items currently in the database by invoking the default report, which is simply the list of items, one after the other. If you are running inside a Python interpreter such as Jupyter Notebook, the visualization is embedded in the web page. If not, a browser opens an HTML page that displays the default report. .. GENERATED FROM PYTHON SOURCE LINES 55-59 .. code-block:: default adr_service.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 60-68 .. image:: /_static/00_create_db_0.png Create tables and trees ----------------------- Table and plot items can be generated by passing a numpy array. Trees are represented via Python dictionaries. All the different options for tables and trees can be set here. .. GENERATED FROM PYTHON SOURCE LINES 69-99 .. code-block:: default my_plot = adr_service.create_item() my_plot.item_table = np.array([[1, 2, 3, 4, 5, 6], [1, 4, 9, 16, 25, 36]], dtype="|S20") my_plot.labels_row = ["First Row", "My Second Row"] leaves = [] for i in range(5): leaves.append({"key": "leaves", "name": f"Leaf {i}", "value": i}) children = [] children.append({"key": "child", "name": "Boolean example", "value": True}) children.append({"key": "child", "name": "Integer example", "value": 10}) children.append( { "key": "child_parent", "name": "A child parent", "value": "Parents can have values", "children": leaves, "state": "collapsed", } ) children.append({"key": "child", "name": "Float example", "value": 99.99}) tree = [] tree.append( {"key": "root", "name": "Top Level", "value": None, "children": children, "state": "expanded"} ) my_tree = adr_service.create_item(obj_name="My Tree object") my_tree.item_tree = tree .. GENERATED FROM PYTHON SOURCE LINES 100-107 Visualize tables and trees -------------------------- You can visualize single items as web components, similarly to how you visualized the default report. Simply calling the :func:`visualize` method on each of the single items. .. GENERATED FROM PYTHON SOURCE LINES 107-110 .. code-block:: default my_plot.visualize() .. GENERATED FROM PYTHON SOURCE LINES 111-113 .. image:: /_static/00_create_db_1.png .. GENERATED FROM PYTHON SOURCE LINES 114-118 .. code-block:: default my_tree.visualize() .. GENERATED FROM PYTHON SOURCE LINES 119-126 .. image:: /_static/00_create_db_2.png 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 127-130 .. code-block:: default # sphinx_gallery_thumbnail_path = '_static/00_create_db_0.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_00-create_db.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00-create_db.py <00-create_db.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00-create_db.ipynb <00-create_db.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_