.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/00-basic/00-basic_example.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-basic_example.py: .. _ref_basic_example: Basic usage =========== This most basic EnSight processing example loads some data from an EnSight installation and generates a simplistic scene. .. GENERATED FROM PYTHON SOURCE LINES 13-17 Start an EnSight session ------------------------ Launch and connect to an instance of EnSight. This example uses a local EnSight installation. .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: default from ansys.pyensight.core import LocalLauncher session = LocalLauncher().start() core = session.ensight.objs.core .. GENERATED FROM PYTHON SOURCE LINES 24-30 Load a dataset -------------- Load some data included in the EnSight installation and set up a slightly rotated view (30 degrees over the X and Y axes). .. image:: /_static/00_basic_0.png .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: default session.load_data(f"{session.cei_home}/ensight{session.cei_suffix}/data/cube/cube.case") session.ensight.view_transf.rotate(30, 30, 0) session.show("image", width=800, height=600) .. GENERATED FROM PYTHON SOURCE LINES 37-42 Create a clip plane ------------------- Create a clip through the volumetric parts. .. image:: /_static/00_basic_1.png .. GENERATED FROM PYTHON SOURCE LINES 42-60 .. code-block:: default clip_default = core.DEFAULTPARTS[session.ensight.PART_CLIP_PLANE] parent_parts = core.PARTS clip = clip_default.createpart(name="Clip", sources=parent_parts)[0] session.show("image", width=800, height=600) print("Parts:", core.PARTS) # .. note:: # There is an issue with the version of PyEnSight that ships with EnSight # 2023 R1. The ``core.DEFAULTPARTS`` attribute may fail with an error # message like this: :samp:`"AttributeError: 'objs' object has no attribute 'ENS_PART_BUILTUP'"`. # A workaround, other than updating the PyEnSight installation, is to use the # :func:`cmd` method: # clip_default = session.cmd("ensight.objs.core.DEFAULTPARTS[ensight.PART_CLIP_PLANE]") .. GENERATED FROM PYTHON SOURCE LINES 61-66 Color the clip plane -------------------- Color the clip plane using the temperature variable. .. image:: /_static/00_basic_2.png .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: default clip.COLORBYPALETTE = core.VARIABLES["temperature"][0] session.show("image", width=800, height=600) print("Variables:", core.VARIABLES) .. GENERATED FROM PYTHON SOURCE LINES 73-82 Change the visual representation -------------------------------- Change the visual representation a bit as follows: #. Display the volume part in border mode instead of feature mode. #. Make the volume part transparent so the clip is still visible. #. Enable element edge display, outlining elements in black lines. .. image:: /_static/00_basic_3.png .. GENERATED FROM PYTHON SOURCE LINES 82-90 .. code-block:: default core.PARTS.set_attr("ELTREPRESENTATION", session.ensight.objs.enums.BORD_FULL) core.PARTS[0].OPAQUENESS = 0.1 d = dict(HIDDENLINE=True, HIDDENLINE_USE_RGB=True, HIDDENLINE_RGB=[0, 0, 0]) core.setattrs(d) session.show("image", width=800, height=600) .. GENERATED FROM PYTHON SOURCE LINES 91-97 Create an annotation -------------------- Create a text annotation and place it near the top of the viewport in the center. .. image:: /_static/00_basic_4.png .. GENERATED FROM PYTHON SOURCE LINES 97-102 .. code-block:: default text = core.DEFAULTANNOTS[session.ensight.ANNOT_TEXT].createannot("Temperature Clip") text.setattrs(dict(LOCATIONX=0.5, LOCATIONY=0.95)) session.show("image", width=800, height=600) .. GENERATED FROM PYTHON SOURCE LINES 103-106 Export content -------------- Save the current image and a GLB file of the scene to disk. .. GENERATED FROM PYTHON SOURCE LINES 106-114 .. code-block:: default pngdata = session.render(1920, 1080, aa=4) with open("simple_example.png", "wb") as fp: fp.write(pngdata) glbdata = session.geometry() with open("simple_example.glb", "wb") as fp: fp.write(glbdata) .. GENERATED FROM PYTHON SOURCE LINES 115-118 Enable direct interaction ------------------------- Open an embedded EnSight window in a browser frame. .. GENERATED FROM PYTHON SOURCE LINES 118-121 .. code-block:: default session.show("remote") .. GENERATED FROM PYTHON SOURCE LINES 122-125 Close the session ----------------- Close the connection and shut down the EnSight instance. .. GENERATED FROM PYTHON SOURCE LINES 125-128 .. code-block:: default # sphinx_gallery_thumbnail_path = '_static/00_basic_4.png' session.close() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download__examples_00-basic_00-basic_example.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-basic_example.py <00-basic_example.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00-basic_example.ipynb <00-basic_example.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_