Basic usage#

This most basic EnSight processing example loads some data from an EnSight installation and generates a simplistic scene.

Start an EnSight session#

Launch and connect to an instance of EnSight. This example uses a local EnSight installation.

from ansys.pyensight.core import LocalLauncher

session = LocalLauncher().start()
core = session.ensight.objs.core

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).

session.ensight.view_transf.rotate(30, 30, 0)"image", width=800, height=600)

Create a clip plane#

Create a clip through the volumetric parts.

clip_default = core.DEFAULTPARTS[session.ensight.PART_CLIP_PLANE]
parent_parts = core.PARTS
clip = clip_default.createpart(name="Clip", sources=parent_parts)[0]"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<ansys.pyensight.core.Session.cmd>` method:
clip_default = session.cmd("ensight.objs.core.DEFAULTPARTS[ensight.PART_CLIP_PLANE]")

Color the clip plane#

Color the clip plane using the temperature variable.

clip.COLORBYPALETTE = core.VARIABLES["temperature"][0]"image", width=800, height=600)
print("Variables:", core.VARIABLES)

Change the visual representation#

Change the visual representation a bit as follows:

  1. Display the volume part in border mode instead of feature mode.

  2. Make the volume part transparent so the clip is still visible.

  3. Enable element edge display, outlining elements in black lines.

core.PARTS.set_attr("ELTREPRESENTATION", session.ensight.objs.enums.BORD_FULL)
core.PARTS[0].OPAQUENESS = 0.1
core.setattrs(d)"image", width=800, height=600)

Create an annotation#

Create a text annotation and place it near the top of the viewport in the center.

text = core.DEFAULTANNOTS[session.ensight.ANNOT_TEXT].createannot("Temperature Clip")
text.setattrs(dict(LOCATIONX=0.5, LOCATIONY=0.95))"image", width=800, height=600)

Export content#

Save the current image and a GLB file of the scene to disk.

pngdata = session.render(1920, 1080, aa=4)
with open("simple_example.png", "wb") as fp:
glbdata = session.geometry()
with open("simple_example.glb", "wb") as fp:

Enable direct interaction#

Open an embedded EnSight window in a browser frame."remote")

Close the session#

Close the connection and shut down the EnSight instance.

# sphinx_gallery_thumbnail_path = '_static/00_basic_4.png'

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery