> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PyEnsight Cheat Sheet

This is a quick-reference guide for [PyEnSight](https://ensight.docs.pyansys.com/version/stable/). Jump to a section of your choosing with these links:

[Launch EnSight](#launch) | [Load data](#load) | [PyEnSight renderables](#render) | [Working with EnSight](#working) | [Saving and restoring](#saving) | [Common graphics operations](#graphics)

## Launch EnSight

Launch EnSight locally:

```python theme={null}
from ansys.pyensight.core import launch_ensight

install = "C:\\ProgramFiles\\ANSYSInc\\v232"
session = launch_ensight(ansys_installation=install)
```

Launch EnSight locally using the launcher:

```python theme={null}
from ansys.pyensight.core import LocalLauncher

install = "C:\\ProgramFiles\\ANSYSInc\\v232"
session = LocalLauncher(
    ansys_installation=install,
    batch=False, # Launch interactive GUI
).start()
```

Launch EnSight locally from a container:

```python theme={null}
from ansys.pyensight.core import DockerLauncher

launcher = DockerLauncher(data_directory="d:/data")
launcher.pull()
session = launcher.start()
```

## Load data

Load an example for postprocessing a design point:

```python theme={null}
session.load_example("elbow_dp0_dp1.ens")
```

Load EnSight, Fluent, or Mechanical data:

```python theme={null}
session.load_data("dataset.encas")
session.load_data("dataset.dvs")
session.load_data("out.cas.h5", result_file="data.dat. h5")
session.load_data("dataset.rst", new_case=True)
# The "new_case" option allows you to create a new case and load multiple datasets in the same EnSight session.
```

## PyEnSight renderables

Create an image renderable:

```python theme={null}
image = session.show("image")
# "image" is a renderable object. Any object returned by the "show()" method is a renderable.
image.browser()
```

Create a deep-pixel picture, ananimation, and a WebGL renderable:

```python theme={null}
session.show("deep_pixel")
session.show("webgl")
session.show("animation")
```

Display the EnSight rendering window:

```python theme={null}
session.show("remote").browser()
session.show("remote").url
# The "url" property is the URL for embedding the renderable in your application. It is available in
# all renderables, like `` browser()`` .
```

## Working with EnSight

Export a picture, a deep-pixel picture, and an animation:

```python theme={null}
export = session.ensight.utils.export
export.image("image.png")
export.image("deep_image.tiff", enhanced=True)
export.animation("animation.mp4")
```

Select parts by a specific dimension:

```python theme={null}
parts = session.ensight.utils.parts
parts.select_parts_by_dimension(3)    # 3D parts
```

Set an isometric view:

```python theme={null}
views = session.ensight.utils.views
views.set_view_direction(1, 1, 1)
```

Query a 1D part and plot the result:

```python theme={null}
query = session.ensight.utils.query
sn = session.ensight.utils.support.scoped_name
with sn(session.ensight.objs.core) as core:
    query.create_distance(
        "my_query",
        query.DISTANCE_PART1D,
        [ensight_1D_object], # ENS_PART
        core.VARIABLES["my_variable"][0],
        new_plotter=True,
    )
```

## Saving and restoring

Save in memory:

```python theme={null}
state = session.capture_context()
```

Save on disk:

```python theme={null}
state.save("state_on_file.ctxz")
```

Restore from memory:

```python theme={null}
session.restore_context(state)
```

Restore from disk:

```python theme={null}
new_ctx = EnsContext()
new_ctx.load("state_in_file.ctxz")
session.restore_context(new_ctx)
```

## Common graphics operations

Color by a variable:

```python theme={null}
attr = "COLORBYPALETTE"
sn = session.ensight.utils.support.scoped_name
with sn(session.ensight.objs.core) as core:
    core.PARTS.set_attr(attr, "velocity")
    core.PARTS[0].setattr(attr, "energy")
    core.PARTS["fluid_domain"].set_attr(attr,"tke")
# The "set_attr()" method is available for a list of EnSight objects,
# while the "setattr()"method is available for a single object.
```

Change the representation:

```python theme={null}
sn = session.ensight.utils.support.scoped_name
with sn(session.ensight.objs.core) as core, sn(
    session.ensight.objs.enums
) as enums:
    # 3D parts border, 2D full
    core.PARTS.set_attr("ELTREPRESENTATION", enums.
        BORD_FULL)
    # High-quality smooth shading
    core.PARTS.set_attr("SHADING", enums.
        SHAD_SMOOTH_REFINED)
```

Show the mesh lines:

```python theme={null}
session.ensight.objs.core.HIDDENLINE = True
session.ensight.objs.core.HIDDENLINE_USE_RGB = True
session.ensight.objs.core.HIDDENLINE_RGB=[0.0, 0.0,
    0.0]
```

## References from PyEnsight documentation

* [Getting started](https://ensight.docs.pyansys.com/version/stable/getting_started/index.html)
* [EnSight API through PyEnSight](https://ensight.docs.pyansys.com/version/stable/class_documentation.html)
* [Examples](https://ensight.docs.pyansys.com/version/stable/_examples/index.html)
