ensight_grpc.EnSightGRPC Class Reference
Last update: 17.04.2023Python binding for the EnSight client gRPC API. More...
Public Member Functions | |
def | __init__ (self, port=12345, host='127.0.0.1', version='') |
create an instance of the EnSight gRPC interface wrapper More... | |
def | host (self) |
get the hostname for this connection More... | |
def | port (self) |
get the port number for this connection More... | |
def | set_security_token (self, n) |
set the security token for the gRPC connection. More... | |
def | security_token (self) |
return the security token for the gRPC connection. More... | |
def | shutdown (self) |
shut down all gRPC connections More... | |
def | start_server (self) |
Start an EnSight gRPC server instance. More... | |
def | stop_server (self) |
shut down any gPRC connection made by this class More... | |
def | is_connected (self) |
check if a gRPC connection has been established More... | |
def | connect (self, timeout=15.0) |
establish a connection to an EnSight gRPC server More... | |
def | render (self, width=640, height=480, aa=1, raw=False, highlighting=False) |
render the current EnSight screen and return the image More... | |
def | geometry (self) |
return the current scene geometry in glTF format More... | |
def | command (self, command_string, do_eval=True, json=False) |
send a Python command string to be executed in EnSight More... | |
def | image_stream_enable (self, flip_vertical=False) |
enable a simple gRPC-based image stream from EnSight More... | |
def | get_image (self) |
retrieve the current EnSight image More... | |
def | image_stream_is_enabled (self) |
check to see if the image stream is enabled More... | |
def | prefix (self) |
return the unique prefix for this instance More... | |
def | event_stream_enable (self) |
enable a simple gRPC-based event stream from EnSight More... | |
def | dynamic_scene_graph_stream (self, client_cmds) |
open up a dynamic scene graph stream More... | |
def | event_stream_is_enabled (self) |
check to see if the event stream is enabled More... | |
def | get_event (self) |
retrieve and remove the oldest ensightservice::EventReply string More... | |
def | subscribe_events (self) |
subscribe to an event stream using a locally launched gRPC server More... | |
def | subscribe_images (self, flip_vertical=False, use_shmem=True) |
subscribe to an image stream More... | |
def | unsubscribe (self) |
unsubscribe from any image or event streams that have been subscribed to More... | |
Detailed Description
Python binding for the EnSight client gRPC API.
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
-
port The port number of the EnSight gRPC server host The hostname of the EnSight gRPC server version A 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 |
|||
) |
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_string the string to be executed do_eval if True, the string will be run via "eval()" and the results returned json If true, the value returned with do_eval() will be encoded via json, otherwise it will be a Python object
Definition at line 245 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
-
timeout how long to wait for the connection to timeout.
Definition at line 174 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_cmds an iterator that produces ensightservice::SceneClientCommand objects
- Returns
- a ensightservice::SceneUpdateCommand stream instance
Definition at line 377 of file ensight_grpc.py.
◆ event_stream_enable()
def ensight_grpc.EnSightGRPC.event_stream_enable | ( | self | ) |
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. These can be retrieved using get_event().
Definition at line 361 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 386 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 227 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 396 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 290 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 72 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_vertical If True, the image will be flipped over the X axis before being sent from EnSight.
Definition at line 273 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 340 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 165 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 78 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 349 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
-
width width in pixels height height in pixels aa number of anti-aliasing passes raw If True, the returned array will be width*height*3 bytes in size. If False, it will be a byte array in PNG format. highlighting If True, the current dynamic selection/highlighting will be in the image
Definition at line 208 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 96 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
-
n an string to be used as the security token
Definition at line 90 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 103 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 126 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 150 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 449 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_vertical If True, the image pixels will be flipped over the X axis use_shmem If True, use the shared memory transport, otherwise use reverse gRPC
Definition at line 465 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 499 of file ensight_grpc.py.
The documentation for this class was generated from the following file:
- D:/ANSYSDev/NoBackup/branches/EnSight-Second-Coming/ensight/client/rpc_interface/ensight_grpc.py