Skip to main content

Post-processing tools 2024 R1

ensight_grpc.EnSightGRPC Class Reference

Last update: 16.07.2025
Inheritance diagram for ensight_grpc.EnSightGRPC:

Public Member Functions

def __init__ (self, port=12345, host='127.0.0.1', version='')
 
def host (self)
 
def port (self)
 
def set_security_token (self, n)
 
def security_token (self)
 
def shutdown (self)
 
def start_server (self)
 
def stop_server (self)
 
def is_connected (self)
 
def connect (self, timeout=15.0)
 
def render (self, width=640, height=480, aa=1, raw=False, highlighting=False)
 
def geometry (self)
 
def command (self, command_string, do_eval=True, json=False, raw_eval=False)
 
def image_stream_enable (self, flip_vertical=False)
 
def get_image (self)
 
def image_stream_is_enabled (self)
 
def prefix (self)
 
def event_stream_enable (self, callback=None, prefix=None)
 
def dynamic_scene_graph_stream (self, client_cmds)
 
def event_stream_is_enabled (self)
 
def get_event (self)
 
def subscribe_events (self)
 
def subscribe_images (self, flip_vertical=False, use_shmem=True)
 
def unsubscribe (self)
 

Protected Attributes

 _host
 
 _port
 
 _pid
 
 _channel
 
 _stub
 
 _dsg_stub
 
 _version
 
 _security_token
 
 _image_stream
 
 _image_thread
 
 _image
 
 _image_number
 
 _shmem_client
 
 _shmem_filename
 
 _event_stream
 
 _event_thread
 
 _events
 
 _prefix
 
 _sub_service
 
 _event_callback
 

Detailed Description

This class provides an asynchronous interface to the EnSight core gRPC interface. It can handle remote image and event streams, providing a much simpler interface to the EnSight application

Definition at line 35 of file ensight_grpc.py.

Constructor & Destructor Documentation

◆ __init__()

def ensight_grpc.EnSightGRPC.__init__ (   self,
  port = 12345,
  host = '127.0.0.1',
  version = '' 
)

create an instance of the EnSight gRPC interface wrapper

The default is to make a connection to an EnSight gRPC server on port 12345 on the loopback host. If requested to launch the server, it will be the current version.

Parameters
portThe port number of the EnSight gRPC server
hostThe hostname of the EnSight gRPC server
versionA specific EnSight version number to run (e.g. '222' for 2022R2)

Definition at line 45 of file ensight_grpc.py.

Member Function Documentation

◆ command()

def ensight_grpc.EnSightGRPC.command (   self,
  command_string,
  do_eval = True,
  json = False,
  raw_eval = False 
)

send a Python command string to be executed in EnSight

The string will be run or evaluated in the EnSight Python interpreter via the EnSightService::RunPython() gRPC all. If an exception or other error occurs, this function will throw a RuntimeError. If do_eval is False, the return value will be None, otherwise it will be the result of eval() of the string.

Parameters
command_stringthe string to be executed
do_evalif True, the string will be run via "eval()" and the results returned
jsonIf true, the value returned with do_eval() will be encoded via json, otherwise it will be a Python object

Definition at line 254 of file ensight_grpc.py.

◆ connect()

def ensight_grpc.EnSightGRPC.connect (   self,
  timeout = 15.0 
)

establish a connection to an EnSight gRPC server

Attempt to connect to an EnSight gRPC server using the host and port established by the constructor. Note on failure, this function just returns, but is_connected() will return False.

Parameters
timeouthow long to wait for the connection to timeout.

Definition at line 177 of file ensight_grpc.py.

◆ dynamic_scene_graph_stream()

def ensight_grpc.EnSightGRPC.dynamic_scene_graph_stream (   self,
  client_cmds 
)

open up a dynamic scene graph stream

Make a DynamicSceneGraphService::GetSceneStream() rpc call and return a ensightservice::SceneUpdateCommand stream instance.

Parameters
client_cmdsan iterator that produces ensightservice::SceneClientCommand objects
Returns
a ensightservice::SceneUpdateCommand stream instance

Definition at line 396 of file ensight_grpc.py.

◆ event_stream_enable()

def ensight_grpc.EnSightGRPC.event_stream_enable (   self,
  callback = None,
  prefix = None 
)

enable a simple gRPC-based event stream from EnSight

This method makes a EnSightService::GetEventStream() gRPC call into EnSight, returning an ensightservice::EventReply stream. The method creates a thread to hold this stream open and read new events from it. The thread adds the event strings to a list of events stored on this instance. If callback is not None, the object will be called with the event string, otherwise they can be retrieved using get_event().

Definition at line 376 of file ensight_grpc.py.

◆ event_stream_is_enabled()

def ensight_grpc.EnSightGRPC.event_stream_is_enabled (   self)

check to see if the event stream is enabled

If an event stream has been successfully established via event_stream_enable(), then this function returns True

Returns
True if a ensightservice::EventReply steam is active

Definition at line 405 of file ensight_grpc.py.

◆ geometry()

def ensight_grpc.EnSightGRPC.geometry (   self)

return the current scene geometry in glTF format

Package up the geometry currently being viewed in the EnSight session as a glTF stream. Return this stream as an array of byte. Note: no interrmediate files are utilized.

Definition at line 235 of file ensight_grpc.py.

◆ get_event()

def ensight_grpc.EnSightGRPC.get_event (   self)

retrieve and remove the oldest ensightservice::EventReply string

When any of the event streaming systems is enabled, Python threads will receive the event records and store them in this instance in an ordered fashion. This method retrieves the oldest ensightservice::EventReply string in the queue.

Returns
the even string or None if no events are available

Definition at line 415 of file ensight_grpc.py.

◆ get_image()

def ensight_grpc.EnSightGRPC.get_image (   self)

retrieve the current EnSight image

When any of the image streaming systems is enabled, Python threads will receive the most recent image and store them in this instance. The frame stored in this instance can be accessed by calling this method

Returns
the image dict(pixels=bytearray, width=w, height=h) and the image frame number

Definition at line 302 of file ensight_grpc.py.

◆ host()

def ensight_grpc.EnSightGRPC.host (   self)

get the hostname for this connection

Returns the current connection hostname.

Definition at line 74 of file ensight_grpc.py.

◆ image_stream_enable()

def ensight_grpc.EnSightGRPC.image_stream_enable (   self,
  flip_vertical = False 
)

enable a simple gRPC-based image stream from EnSight

This method makes a EnSightService::GetImageStream() gRPC call into EnSight, returning an ensightservice::ImageReply stream. The method creates a thread to hold this stream open and read new image frames from it. The thread places the read images in this object. An external application can retrieve the most recent one using get_image().

Parameters
flip_verticalIf True, the image will be flipped over the X axis before being sent from EnSight.

Definition at line 284 of file ensight_grpc.py.

◆ image_stream_is_enabled()

def ensight_grpc.EnSightGRPC.image_stream_is_enabled (   self)

check to see if the image stream is enabled

If an image stream has been successfully established via image_stream_enable(), then this function returns True

Returns
True if a ensightservice::ImageReply steam is active

Definition at line 354 of file ensight_grpc.py.

◆ is_connected()

def ensight_grpc.EnSightGRPC.is_connected (   self)

check if a gRPC connection has been established

Returns True if a previous connect() call made a valid gRPC connection.

Definition at line 168 of file ensight_grpc.py.

◆ port()

def ensight_grpc.EnSightGRPC.port (   self)

get the port number for this connection

Returns the current connection port number.

Definition at line 80 of file ensight_grpc.py.

◆ prefix()

def ensight_grpc.EnSightGRPC.prefix (   self)

return the unique prefix for this instance

Many of the EnSight gRPC APIs require a unique prefix so that EnSight can handle multiple, simultaneous remote connections. This method will generate a GUID-based prefix.

Returns
A unique prefix string of the form: grpc://{uuid}/

Definition at line 363 of file ensight_grpc.py.

◆ render()

def ensight_grpc.EnSightGRPC.render (   self,
  width = 640,
  height = 480,
  aa = 1,
  raw = False,
  highlighting = False 
)

render the current EnSight screen and return the image

Render the current scene at some resolution independent of the current EnSight scene view.

Parameters
widthwidth in pixels
heightheight in pixels
aanumber of anti-aliasing passes
rawIf True, the returned array will be width*height*3 bytes in size. If False, it will be a byte array in PNG format.
highlightingIf True, the current dynamic selection/highlighting will be in the image

Definition at line 215 of file ensight_grpc.py.

◆ security_token()

def ensight_grpc.EnSightGRPC.security_token (   self)

return the security token for the gRPC connection.

Returns the current connection security token

Definition at line 98 of file ensight_grpc.py.

◆ set_security_token()

def ensight_grpc.EnSightGRPC.set_security_token (   self,
  n 
)

set the security token for the gRPC connection.

EnSight supports a security token in either numeric (-security {int}) or string (ENSIGHT_SECURITY_TOKEN environmental variable) form. If EnSight is using a security token, all gRPC calls must include this token. This call sets the token for all rGPC calls made by this class. Note: for this module, the security token must be a in bytes() format. For example: str(1000).encode("utf-8")

Parameters
nan string to be used as the security token

Definition at line 92 of file ensight_grpc.py.

◆ shutdown()

def ensight_grpc.EnSightGRPC.shutdown (   self)

shut down all gRPC connections

If this class launched the EnSight client instance, it will send the gRPC exit() call and then shut down all connections.

Definition at line 105 of file ensight_grpc.py.

◆ start_server()

def ensight_grpc.EnSightGRPC.start_server (   self)

Start an EnSight gRPC server instance.

If the host application wishes to launch an EnSight instance, start_server() will launch a batch mode EnSight application with the security token and a gRPC server started on the port passed in the constructor.

Definition at line 128 of file ensight_grpc.py.

◆ stop_server()

def ensight_grpc.EnSightGRPC.stop_server (   self)

shut down any gPRC connection made by this class

First, if this class launched the EnSight instance, via start_server(), the exit() gRPC command will be sent. Second, the local gRPC connection is dropped.

Definition at line 153 of file ensight_grpc.py.

◆ subscribe_events()

def ensight_grpc.EnSightGRPC.subscribe_events (   self)

subscribe to an event stream using a locally launched gRPC server

This methond makes a EnSightService::SubscribeEvents() gRPC call, causing EnSight to make a reverse gRPC connection over with gRPC calls with the various events will be made.

Definition at line 471 of file ensight_grpc.py.

◆ subscribe_images()

def ensight_grpc.EnSightGRPC.subscribe_images (   self,
  flip_vertical = False,
  use_shmem = True 
)

subscribe to an image stream

This methond makes a EnSightService::SubscribeImages() gRPC call. If use_shmem is False, the transport system will be made over gRPC. It causes EnSight to make a reverse gRPC connection over with gRPC calls with the various images will be made. If use_shmem is True (the default), the EnSight gRPC Shared Memory Image Transport API will be used.

Parameters
flip_verticalIf True, the image pixels will be flipped over the X axis
use_shmemIf True, use the shared memory transport, otherwise use reverse gRPC

Definition at line 488 of file ensight_grpc.py.

◆ unsubscribe()

def ensight_grpc.EnSightGRPC.unsubscribe (   self)

unsubscribe from any image or event streams that have been subscribed to

This method makes a EnSightService::Unsubscribe() gRPC call. It will cancel any subscribe_events() or subscribe_images() calls.

Definition at line 527 of file ensight_grpc.py.

Member Data Documentation

◆ _channel

ensight_grpc.EnSightGRPC._channel
protected

Definition at line 49 of file ensight_grpc.py.

◆ _dsg_stub

ensight_grpc.EnSightGRPC._dsg_stub
protected

Definition at line 51 of file ensight_grpc.py.

◆ _event_callback

ensight_grpc.EnSightGRPC._event_callback
protected

Definition at line 68 of file ensight_grpc.py.

◆ _event_stream

ensight_grpc.EnSightGRPC._event_stream
protected

Definition at line 63 of file ensight_grpc.py.

◆ _event_thread

ensight_grpc.EnSightGRPC._event_thread
protected

Definition at line 64 of file ensight_grpc.py.

◆ _events

ensight_grpc.EnSightGRPC._events
protected

Definition at line 65 of file ensight_grpc.py.

◆ _host

ensight_grpc.EnSightGRPC._host
protected

Definition at line 46 of file ensight_grpc.py.

◆ _image

ensight_grpc.EnSightGRPC._image
protected

Definition at line 58 of file ensight_grpc.py.

◆ _image_number

ensight_grpc.EnSightGRPC._image_number
protected

Definition at line 59 of file ensight_grpc.py.

◆ _image_stream

ensight_grpc.EnSightGRPC._image_stream
protected

Definition at line 56 of file ensight_grpc.py.

◆ _image_thread

ensight_grpc.EnSightGRPC._image_thread
protected

Definition at line 57 of file ensight_grpc.py.

◆ _pid

ensight_grpc.EnSightGRPC._pid
protected

Definition at line 48 of file ensight_grpc.py.

◆ _port

ensight_grpc.EnSightGRPC._port
protected

Definition at line 47 of file ensight_grpc.py.

◆ _prefix

ensight_grpc.EnSightGRPC._prefix
protected

Definition at line 66 of file ensight_grpc.py.

◆ _security_token

ensight_grpc.EnSightGRPC._security_token
protected

Definition at line 53 of file ensight_grpc.py.

◆ _shmem_client

ensight_grpc.EnSightGRPC._shmem_client
protected

Definition at line 60 of file ensight_grpc.py.

◆ _shmem_filename

ensight_grpc.EnSightGRPC._shmem_filename
protected

Definition at line 61 of file ensight_grpc.py.

◆ _stub

ensight_grpc.EnSightGRPC._stub
protected

Definition at line 50 of file ensight_grpc.py.

◆ _sub_service

ensight_grpc.EnSightGRPC._sub_service
protected

Definition at line 67 of file ensight_grpc.py.

◆ _version

ensight_grpc.EnSightGRPC._version
protected

Definition at line 52 of file ensight_grpc.py.


The documentation for this class was generated from the following file:

Connect with Ansys