-grpc_server port. EnSight supports the gRPC server interface in both batch and full UI modes and if no port is specified, the default port is: 18243. For example, EnSight can be launched in batch with the gRPC server interface enabled with the command:
Security token
The gRPC interface supports the EnSight shared secret security token as well. If EnSight has been launched with a security token enabled, the token must be passed in the metadata with every gRPC method invocation. EnSight can be launched with-security {number} on the command line or one can set the environmental variable: ENSIGHT_SECURITY_TOKEN to the token string. The example illustrates how the token is added to the metadata. Note, the environmental variable is a more secure approach than the command line option.
Built-in example
All the necessary Python grpc modules are included in the EnSightcpython distribution. To run the example program, one can use the following commands:
v261\CEI\ensight261\site_preferences\extensions\. Files include:
-
build.sh- a script file that compiles the .proto file into Python modules -
ensight.proto- the gRPC protocol specification -
ensight_grpc.py- a module that wraps the gRPC protocol with a simplified interface (see below) -
qt_gui.py- a Python PyQt GUI application that launches EnSight and talks to it via gRPC
Simple Python example (for a non-Ansys Python distribution)
In this example, we will configure a Python instance to connect to EnSight and enable it to make gRPC calls. The first step is to get a Python interpreter instance up and running with the necessary gRPC modules installed. The example code here assumes the command ‘python’ will launch a platform native Python 3.x interpreter.v261/CEI/ensight261/site_preferences/extensions/grpc.
Streaming APIs
The streaming interfaces are largely wrapped in the example above. The client application starts the streams by making the gRPC GetEventStream or GetImageStream calls. These return streams of EventReply and ImageReply protobuf objects respectively. These will continue to send values until the starting methods are ended (effectively, these are serviced by asynchronous threads running in the EnSight client application). The wrapper above creates Python threads to read protocol buffers and place them into the interface object (EnSightGRPC) for later access by the calling application. The complex example (qt_gui.py) contains one example of how these might be interfaced into your client application.Event streaming API
The event stream is tied into the EnSight Python attribute callback API (see these docs). When Python code running in EnSight calls:EnSight gRPC Interface://MYTAG/VISIBLE?enum=VISIBLE&uuid=233 when the visibility of the first part (note that ensight.objs.core.PARTS[0].objid == 223 in the example) changes. See the qt_gui.py and ensight_grpc.py for more examples. Note: there is nothing special about the EnSight gRPC Interface://MYTAG/VISIBLE name, it could be any string. It is handy to allow the URI parser to handle parsing as the core will append the ‘enum’ and ‘uuid’ query stanzas to the tag automatically.