.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/25-intermediate/02-json.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_25-intermediate_02-json.py: .. _ref_json: Import or export report template using JSON =========================================== Ansys Dynamic Reporting provides a seamless solution for serializing and deserializing report templates. It allows you to export templates as local JSON files and rebuild them through JSON imports. This section describes the process of converting a report template and loading it back in. .. note:: This example assumes that you have a local Ansys installation. .. GENERATED FROM PYTHON SOURCE LINES 19-24 Start a new Ansys Dynamic Reporting service ------------------------------------------- Start a new ADR service. Make sure the database directory is empty. Use the get_list_report method to check that there are no reports in the database. .. GENERATED FROM PYTHON SOURCE LINES 24-34 .. code-block:: Python import ansys.dynamicreporting.core as adr import ansys.dynamicreporting.core.examples as examples adr_service = adr.Service( ansys_installation=r"C:\Program Files\ANSYS Inc\v251", db_directory=r"C:\tmp\new_template" ) adr_service.start(create_db=True) adr_service.get_list_reports() .. GENERATED FROM PYTHON SOURCE LINES 35-40 Create a new report template from the JSON file ------------------------------------------------ Download a JSON sample file for the report templates. Load it into the ADR service. Check that the ADR service now contains a report. Visualize it. .. GENERATED FROM PYTHON SOURCE LINES 41-48 .. code-block:: Python template_path = examples.download_file("report_template.json", "multi_physics") adr_service.load_templates(template_path) adr_service.get_list_reports() new_report = adr_service.get_report("Solution Analysis from Multiphysics simulation") new_report.visualize() .. GENERATED FROM PYTHON SOURCE LINES 49-58 .. image:: /_static/report_json_vis.png :scale: 50% Modify and export the report template ------------------------------------- Add a new chapter to the report template using the low level API. Export the new JSON file corresponding to the changed report, and visualize it. Note the extra chapter in the Table Of Contents, corresponding to the change you just made. .. GENERATED FROM PYTHON SOURCE LINES 59-72 .. code-block:: Python server = adr_service.serverobj new_chapter = server.create_template( name="Appendix", parent=new_report.report, report_type="Layout:basic" ) new_chapter.params = '{"TOCitems": 1, "HTML": "

Appendix

", "properties": {"TOCItem": "1", "TOCLevel": "0", "justification": "left"}}' new_chapter.set_filter("A|i_tags|cont|section=appendix;") server.put_objects(new_chapter) server.put_objects(new_report.report) new_report.visualize() new_report.export_json("modified_report.json") .. GENERATED FROM PYTHON SOURCE LINES 73-82 .. image:: /_static/export_json_vis.png :scale: 50% .. note:: If the name of the loaded report conflicts with an existing name in the service (for example, when reloading the same report as in the previous step), Ansys Dynamic Reporting automatically renames the loaded report. In this case, the report will be renamed to "my_report_name (1)". .. GENERATED FROM PYTHON SOURCE LINES 85-90 Close the service ----------------- Close the Ansys Dynamic Reporting service. The database with the report template that was created remains on disk. .. GENERATED FROM PYTHON SOURCE LINES 90-93 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/default_thumb.png' adr_service.stop() .. _sphx_glr_download_examples_25-intermediate_02-json.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02-json.ipynb <02-json.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02-json.py <02-json.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02-json.zip <02-json.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_