.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-basic/01-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_01-create_db.py: .. _ref_createdb: Create a database and populate it ================================= 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-32 .. code-block:: Python import numpy as np import ansys.dynamicreporting.core as adr import ansys.dynamicreporting.core.examples as examples 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 33-39 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 39-47 .. code-block:: Python 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 = examples.download_file("enthalpy_001.png", "input_data") my_scene = adr_service.create_item() my_scene.item_scene = examples.download_file("dam_break.avz", "input_data") .. GENERATED FROM PYTHON SOURCE LINES 48-56 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 56-60 .. code-block:: Python adr_service.visualize_report() .. GENERATED FROM PYTHON SOURCE LINES 61-69 .. 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 70-100 .. code-block:: Python 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 101-108 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 108-111 .. code-block:: Python my_plot.visualize() .. GENERATED FROM PYTHON SOURCE LINES 112-114 .. image:: /_static/00_create_db_1.png .. GENERATED FROM PYTHON SOURCE LINES 115-119 .. code-block:: Python my_tree.visualize() .. GENERATED FROM PYTHON SOURCE LINES 120-127 .. 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 128-131 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/00_create_db_0.png' adr_service.stop() .. _sphx_glr_download_examples_00-basic_01-create_db.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-create_db.ipynb <01-create_db.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-create_db.py <01-create_db.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01-create_db.zip <01-create_db.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_