8.1. Python EnSight Module Interface

Key to interacting with EnSight from within Python is the ensight module. This module is pre-loaded into the environment and provides a number of methods that can be used to communicate directly with EnSight. There are a large number of examples that use this interface included in the user-defined EnSight extensions. These can be found in the $CEI/ensight242/site_preferences/extensions/user_defined directory tree.

Interpreter Startup

When the EnSight Python interpreter is initialized it performs the following operations:

  1. Set up PYTHON_HOME/PATH.

  2. Create the ensight module.

  3. Create the cmdlanguage methods in the ensight module for the native API.

  4. Import the sys, sip and imp modules.

  5. Import the PyQt4.Gui module.

  6. Add $CEI/ensight242/site_preferences/extensions to sys.path.

  7. If it exists, add the EnSight Defaults Directory path plus the extensions subdirectory to sys.path. The EnSight Defaults Directory path is %HOMEDRIVE%%HOMEPATH%\(username)\.ensight242 commonly C:\Users\username\.ensight242 Win10, ~/.ensight242 on Linux, and ~/Library/Application Support/ensight242 on the Mac.

  8. Import the ensight.core module. This has the side effect of adding the names specified by the CEI_PYTHONPATH environmental variable (: separated under Unix and ; separated under Windows) to sys.path.

  9. Execute ensight.core.load_extensions(). This walks the extension tree, loads any user defined extensions and reads in any Qt4 language files (*.qm) it finds.

EnSight Module Methods

ensight.sendmesg(cmd|(cmdlist)[,record=r] [,display=d] [,exception=e] [,version=v] [,noexec=n])

This method executes one or more command language commands. The function can be passed a single string or a tuple of strings. In the latter case, all the strings in the tuple will be executed. For example:

ensight.sendmesg(("shell: echo A", "shell: echo B")) executes two command language commands. The sendmesg() function provides mechanisms to control the display and recording of the individual command language commands it executes. The 'record=' and 'display=' keyword arguments control this. By default, commands are not recorded in the session command log. If the record keyword is set to 1, the commands will be recorded in the session log. For example: ensight.sendmesg("shell: echo hello",record=1) will execute the command and cause it to be recorded. If the display keyword is set to '1', the commands will be echoed as text as they are executed to the Python text log in the command dialog Python tab. Similarly, the 'noexec=' keyword controls if the command being issued should actually be executed. Setting noexec to 1 suppresses actual execution of the command, but still allows for the command to be displayed or recorded as selected by other keywords.

This method returns a 0 if no error and a -1 if error. For example we can purposely enter in the correct rotate command and an incorrect rotate command and show the return values:

a = ensight.sendmesg("view_transf: rotate -1 1 0")

print(a)

0

a = ensight.sendmesg("view_transf: rotERRORate -1 1 0")

print(a)

-1

If the exception keyword is set to 1, and the command language string resulted in an error, Python will raise a Python exception instead of returning -1, which can be trapped by normal Python exception handling mechanisms.

If the version keyword is set, the version of the command language will be set to that version for the duration of this single command. The default is to use the version set by sendmesgoptions(). If the keyword is set to 0, the current version of EnSight is used.

Explicitly setting any keywords will override the defaults set by the ensight.sendmesgoptions() method.


Note:  You can send the commands that open a part of the current EnSight graphical user interface with this method. See GUI raw commands


ensight.sendmesgoptions([record=r] [,display=d] [,exception=e] [,version=v] [,noexec=n])

This method allows the caller to set the default values for the exception, record, display, version and noexec keywords in the ensight.sendmesg() method. By default, the keywords except 'version' are set to 0. If they are set to 1 by this method, subsequent sendmesg() calls without the keywords specified will use the values set by this method. For example:

ensight.sendmesgoptions(record=1,display=1)

ensight.sendmesg("shell: echo A")

will result in the shell: command being both logged and printed. The commands: ensight.sendmesgoptions(record=1,display=1)

ensight.sendmesg("shell: echo A",record=0) would result in the shell: command being printed, but not recorded. The noexec keyword can be set to 1 to allow the record and display operations to run as selected, but actual execution of the line of command language is suppressed.

By default, version is set to the current EnSight command language version number. The keyword can be set to any valid floating point version number. If it is set to 0, the version will be reset to the version of EnSight running (its initial state).

(value,type,scope) = ensight.ensvariable(varname)

 

This method will query EnSight command language variable values and returns a tuple containing the value, its type and the scope it was found in (similar to the command language $ functionality, allowing access to variables defined directly in command language or computed constants). The function returns None if the variable cannot be found.

The TYPE of the variable will be 0 if the value is an integer, 1 if the value is a float and 2 if the value is a string.

The SCOPE is an integer that specifies where the variable was found.

-2: the variable is in the enscl namespace (for example, ensight.ensvariable(enscl.FOO)).

-1: the variable is an EnSight constant variable (file, case or computed variable).

0: the variable is global in the command language interpreter (for example, $globalint BAR) or is a special command language variable like: APPTOTALTIMESTEPS.

+1: the variable is local in the command language interpreter and the number is the depth in the interpreter stack where the value is defined.

ensight.play(filename)

 

This method causes the command language file (.enc) specified by FILENAME to be executed (similar to the play: filename command). If the name of a Python (.py) file is specified, the file will be read into memory and executed with the Python 'exec()' command.

ensight.reparent(QWidget_object)

 

This method is useful on X11 platforms and harmless under Windows. It causes any PyQt widgets one might create in the EnSight Python interpreter to properly layer with the EnSight windows (keeping them above the main EnSight window).


Note:  Calling this function with the wrong argument type can cause EnSight to crash.


(err, value, ...) = ensight.query(param[,which])

 

This method allows the caller to query various attributes in EnSight. The returned value is always a list that starts with an error code. The list will include one or more returned values (specific to the param). See Query Capability.

Valid param values include the following:

ensight. FRAME_COUNT

ensight. FRAME_LOCATION *

ensight. LEGEND_COUNT

ensight. LEGEND_DISPLAY_ATTRIBUTES *

ensight. LEGEND_SELECTED_OBJECTS

ensight. LINE_COUNT

ensight. LINE_DISPLAY_ATTRIBUTES *

ensight. LINE_SELECTED_OBJECTS

ensight. LOGO_COUNT

ensight. LOGO_DISPLAY_ATTRIBUTES *

ensight. LOGO_SELECTED_OBJECTS

ensight. DIAL_COUNT

ensight. DIAL_DISPLAY_ATTRIBUTES *

ensight. DIAL_SELECTED_OBJECTS

ensight. FLIPBOOK_INFORMATION

ensight. FLIPBOOK_LOADED

ensight. FLIPBOOK_RUNNING

ensight. GAUGE_COUNT

ensight. GAUGE_DISPLAY_ATTRIBUTES *

ensight. GAUGE_SELECTED_OBJECTS

ensight. SHAPE_COUNT

ensight. SHAPE_DISPLAY_ATTRIBUTES *

ensight. SHAPE_SELECTED_OBJECTS

ensight. ARROW_COUNT

ensight. ARROW_DISPLAY_ATTRIBUTES *

ensight. ARROW_SELECTED_OBJECTS

ensight. ARROW_LABEL_TEXT

ensight. MESSAGES

ensight. PART_DISPLAY_ATTRIBUTES *

ensight. PART_ELEMENT_PICKEDBYWINXY * *

ensight. PART_ELEMENT_PICKEDBYWORLDXYZ * * * *

ensight. PART_NODE_PICKEDBYWINXY * *

ensight. PART_NODE_PICKEDBYWORLDXYZ * * * *

ensight. PART_OBJECTS

ensight. PART_PICKED * *

ensight. PART_SELECTED_OBJECTS

ensight. PLOT_COUNT

ensight. PART_DISPLAY_ATTRIBUTES *

ensight. PLOT_PICKED * *

ensight. QUERY_COUNT

ensight. QUERY_DISPLAY_ATTRIBUTES

ensight. QUERY_PICKED * *

ensight.QUERY_PROBE_DATA

ensight. QUERY_PROBE_OUTPUT *

ensight. QUERY_PROBE_ATTRIBUTES

ensight. TEXT_COUNT

ensight. TEXT_DISPLAY_TEXT *

ensight. TEXT_DISPLAY_ATTRIBUTES *

ensight. TEXT_SELECTED_OBJECTS

ensight. TRANSFORMATION_PERANG *

ensight. TRANSFORMATION_PROJ_MATRIX *

ensight. TRANSFORMATION_CENTER_OF *

ensight. TRANSFORMATION_COMPOSITE_MATRIX *

ensight. TRANSFORMATION_LOOKAT_POSITION *

ensight. TRANSFORMATION_LOOKFROM_POSITION *

ensight. TRANSFORMATION_ROTATE_MATRIX *

ensight. TRANSFORMATION_SCALE_MATRIX *

ensight. TRANSFORMATION_TRANSLATE_MATRIX *

ensight. TRANSFORMATION_ZCLIP_LOCATIONS *

ensight. VARIABLE_OBJECTS

ensight. VARIABLE_INFORMATION *

ensight. VIEWPORT_COUNT

ensight. VIEWPORT_DISPLAY_ATTRIBUTES *

ensight. VIEWPORT_LOCATION *

ensight. VIEWPORT_SIZE *

ensight. WINDOW_SIZE

ensight. WINDOW_DEPTH_VALUES

ensight. WINDOW_RGBA_VALUES


Note:  An * means the which argument is required.


† The ensight.WINDOW_RGBA_VALUES is a special case. The second argument value picks the format of the returned data. A 0 returns the image as a list of integers, 1 returns the image as an ASCII string (which happens to be a valid .ppm file) and 2 returns the image as an enve image object

The following query param() options are specific to the Python interface and are not supported by the command driver interface:

ensight.TEXTURE_COUNT

Returns the number of textures EnSight supports.

 

ensight.TEXTURE_IMAGE *

Returns the texture selected by param1 as an EnVe image object (see the EnVe module description of the image object).

ensight.TEXTURE_BORDER_COLOR *

Returns the texture border color [R,G,B,A] selected by param1.

ensight.VARIABLE_PALETTE * [*]

Returns the current palette for the variable index (see ensight.VARIABLE_OBJECTS ) selected by param1. If the variable is a vector, param2 selects the palette for the magnitude (0), x (1), y (2) or z (3) components (it defaults to 0). Each palette entry is four values in the floating point array. The first is the value and the next three are the R, G, B color for that value.

ensight.CMDLANG_VERSION

Returns the current EnSight command language version number being used. The value is returned as a string.

ensight.VARIABLE_HISTOGRAM *

Returns the min, max and current histogram for the variable index (see ensight.VARIABLE_OBJECTS) selected by param1. For a scalar variable, 102 floating point values are returned. The first two are the variable min and max respectively. The subsequent 100 values are the counts for 100 bins between the min and max values. For vector variables, four times the number of values are returned. Values for the magnitude and x, y, and z components are included.

ensight.QUERY_DATA *

For the query selected by param1 (see ensight.QUERY_COUNT ), this values returns the actual point data for that query. The routine returns integer, string and float values. The integers start with the number of columns. These will be 2 or 5 depending on the type of query (for example, over time or over distance). The remaining integers define the number of point that go into each segment. The (2 or 5) strings are the labels for the columns. The floating point values will be either 2 or 5 per point and there will be as many points as the sum of the integers following the number of columns.

Example 8.1: ensight.QUERY_DATA *

num_queries = ensight.query(ensight.QUERY_COUNT)
print("The number of queries is {}".format(num_queries[1])
for query_num in range(num_queries[1][0]):
    query_vals = ensight.query(ensight.QUERY_DATA,query_num)
    print("query vals, query num {} = {}".format(query_num, query_vals))


ensight.QUERY_PROBE_DATA

Returns the current interactive probe query values. The output is a list, one item per query value. Each item is a list of the form:

[[variables], [xyz], [ijk], ID, type]

The first item in the output list contains text headers for all the columns. The variables list contains one item for each selected variable. The xyz list contains a list of three floats, the coordinates of the query. The ijk list (which can be null) contains a list of three ints, the ijk values of the query (if any). If the query has an ID value, it will be returned ad ID (or the value will be null). The type of the query is an ASCII string of the source of the query.


Note:  Undefined values will be returned as Python None objects.


Example for a simple query with two probes and two variables:

print(ensight.query(ensight.QUERY_PROBE_DATA))
[
    [[‘temperature’, ‘velocity’], [‘X’,’Y’,’Z’], [‘I’,’J’,’K’], ‘ID’,
‘Type’],
    [[0.9, 0.9], [1.5, -2.0, 0.9], [None, None, None], None, ‘Surface
Pick’],
    [[0.9, 0.9], [-0.8, -2.0, 0.9], [None, None, None], None, ‘Surface
Pick’]
]

ensight.DATASET

Returns information about the current dataset. The output may be None if the current case is not loaded of a list of the form:

[[filedata],coord_sys,coord_type,full_flag,[[minx,miny,minz],

[maxx,maxy,maxz]], total_nodes, total_elements, [elementlist]]

The FILEDATA list describes the various files opened (as specified by the actual reader). The information includes the filename, its size, its date and any number of description strings. The list has the form:

[[filename,file_size,file_date,["desc1","desc2",...]]

COORD_SYS specifies the file's coordinate system and can be: Cylindrical, Rectangular, Spherical or Unknown. COORD_TYPE specifies the file's temporal scheme and can be: Static, Changing Connectivity or Changing Coordinate.

The FULL_FLAG is 1 if the min/max arrays are for the entire dataset. Otherwise the numbers are just for the loaded parts. The subsequent arrays specify the coordinate min/max values for x, y and z.

TOTAL_NODES and TOTAL_ELEMENTS specify the total number of nodes and elements in the dataset respectively. The ELEMENTLIST list describes the number of elements in the dataset of each element type. The list has the form:

[["type1",num_elements1],["type2",num_elements2],...]

ensight.TIMEVALS

This query returns a dictionary of the current EnSight timeline. The dictionary keys include:

timecurrent - the current time value

stepcurrent - the current timestep (note: this is a float as it could be interpolated)

timelimits - list of the minimum and maximum time values

steplimits - list of the minimum and maximum time steps (integers)

timevalues - list of [timestep, timevalues] lists for every simulation time

ensight.FULLSCREEN

This query returns zero if EnSight is not in fullscreen mode or non-zero if it is in fullscreen mode.

ensight.PREFERENCESPATH

This query returns a string that is the directory name where EnSight is reading and writing preference data to.

ensight.SENDMESG_RECORD,SENDMESG_RAISE,SENDMESG_NOEXEC,SENDMESG_DISPLAY

These four queries return the current value of the record, exception, noexec or display named arguments respectively to the ensight.sendmesgoptions() method.

ensight.GLCONFIG

This query returns a dictionary of OpenGL related information. The dictionary keys include (on most platforms):

vendor - the OpenGL vendor string

renderer - the OpenGL renderer string

version - the OpenGL version string

stencilbuffer - a non-zero integer if a stencil buffer is being used

doublebuffer - a non-zero integer if depth buffering is being used

occlusiontest - True if the OpenGL occlusion test is being used

wirefamemode - True if wireframe mode is done with lines (instead of polygons)

displaylist - True if OpenGL display lists are being used

normpervertex - True if EnSight is generating a normal per vertex

vertexcount - the number of vertices in a geometry block

palettemode - "Textures" or "RGB"

extensions - the OpenGL extension string

freevideoram - Amount of available GPU memory, in MB (If 0, then graphics card or software driver does not allow a query of memory).

ensight.SYSINFO

This query returns a dictionary of system resource related information. The dictionary keys include (on most platforms):

numprocs - number of processor (cores) in the system

totalmem - amount of physical RAM in the system (in kilobytes)

freemem - amount of free RAM in the system (in kilobytes)

memuse - the amount of RAM being used by the EnSight process (in kilobytes)

pointersize - the size of a pointer in bits on the platform (32 or 64)

ensight.DR_INFO

This query returns a dictionary of system resource related information. The dictionary keys include (on most platforms):

parallelrendering - a non-zero integer if the system is using parallel rendering

masterclient - True if the current node is the DR master client

compositing - True if image-based parallel compositing is being used

detached - True if DR detached displays are being used

rank - the rank of the current EnSight client node in DR

ranksize - the number of clients nodes being used in this DR session.

ensight.UNIQUE_ID

This query returns a unique integer number every time it is called. This can be useful with things like obtaining a unique, private filter flag for the ENS_EVENT_PYTHON event interface.

ensight.SPLINE_COUNT

This query returns the number of splines currently defined. The value is returned as with the command driver queries: [errorcode, [number_of_splines]].

ensight.SPLINE_DATA

This query returns the actual raw splince coordinates for a given spline number. For example:

a = ensight.query(ensight.SPLINE_DATA, 1)

returns the control points for spline number 1. The spline data itself has the following form:

[errorcode,[num_points],[x0,y0,z0,x1,y1,

z1...],['spline name']]

ensight.TOOL_PARAMS *

Allows the user to query the current setting for the various EnSight data tools.

The param1 value should be one of the following:

ensight.TOOL_CURSOR

Value is three floats: [x,y,z] the point

ensight.TOOL_LINE

Value is six floats: [x0,y0,z0,x1,y1,z1] two points

ensight.TOOL_PLANE

Value is twelve floats:

[x0,y0,z0,x1,y1,z1,x2,

y2,z2,x3,y3,z3] four points

(must be rectangular and co-planar)

ensight.TOOL_BOX

Value is fifteen floats:

[ox,oy,oz,xx,xy,xz,yx,yy,

yz,zx,zy,zz,sx,sy,sz] an origin point, three 

normal vectors (must be orthogonal) 

for the axis and three length values

ensight.TOOL_CYLINDER

Value is seven floats: [x0,y0,z0,x1,y1,z1,rad] two points at the ends of the cylinder and the radius

ensight.TOOL_SPHERE

Value is six floats: [x0,y0,z0,x1,y1,z1] two points that define the diameter (and major axis) of the sphere.

ensight.TOOL_CONE

Value is seven floats:

[x0,y0,z0,x1,y1,z1,

cone_ang] two points at the ends of the 

cone and the angle at the apex.

ensight.TOOL_REVOLUTION

Value is six + 2*N floats:

[x0,y0,z0,x1.y1.

z1,d0,r0,d1,r1,...] two point, one at the end and

the other that defines the axis followed by

a variable number of distance, radius pairs

that define the profile

err = ensight.modify(param,(value))

This method is used to set various EnSight global parameters.

The valid values for param are:

ensight.TEXTURE_IMAGE

In this case, value should be a tuple of the form (texure_index, image). Texture_index is an integer from 0 to 7 and image is an EnVe module image object.

ensight.TEXTURE_BORDER_COLOR

In this case, value should be a tuple of the form (texure_index,(r,g,b,a)). Texture_index is an integer from 0 to 7, while (r,g,b,a) is a four valued float tuple that specifies a color+alpha value (all values are in the range [0,1]).

ensight.TOOL_PARAMS

In this case, value should be a tuple of the form (tool_name, (tool_setting)). Tool_name is one of the options documented for TOOL_PARAMS for ensight.query() above (for example, ensight.TOOL_CURSOR). Tool_setting is the value to change to change the tool location/settings to (see the TOOL_PARAMS section in the ensight.query() documentation for details on the individual tool formats.

ensight.refresh()

This method queues up an EnSight redraw for the next idle redraw of its graphics displays. Use the following to force the redraw immediately: ensight.refresh(force=1) .

image = ensight.render([x=dx] [,y=dy] [,dpi=dpi] [,stereo=s] [,plots_only=po] [,invert_background=ib][,num_samples=ns])

This method causes EnSight to render the current image to one or more EnVe image objects. The return value is either a single EnVe image object by default. If the stereo keyword is set to 1, the return value will be a list of two image objects. The first is the left eye view and the second the right eye view. By default, the output image(s) will be the size of the current EnSight rendering window. The x and y keywords can be set to any desired output image size. The dpi keyword selects the dots per inch resolution of the output. In the current release, this keyword is ignored. When set to 1, the plots_only keyword will cause only the EnSight plots to be drawn instead of both the plots and the geometry. When set to 1, the invert_background keyword will cause the current background to toggle between black and white. This can be useful if the ultimate target of the image is a printer or perhaps an embedded document. The num_samples keyword sets the number of passes of full scene anti-aliasing that should be used to render the output image. The default number of samples is 1 and the maximum number is 16. If the enhanced keyword is set to 1, EnSight will render the current scene in Deep Pixel mode, capturing the variable data exposed on the surfaces and the part that each pixel corresponds to in the image. See Deep Pixel for more information.

value = ensight.query_points(pointlist [,parts=partlist] [,variables=varlist] [,time=t])

This function is a basic variable and mesh query mechanism. It takes a list of points as input. The list is a Python list of 3 value python lists. An example would be: [ [1,2,0], [2,4,2] ] for two points. The function will perform a query at each point in the list.

The parts keyword variable is optional. If not present, the currently selected parts will be used. The parts keyword can be set to the string all (for example, parts="all") to select all parts in the current case, otherwise, partlist should be a Python list variable may include any mixture of string names, part numbers or part objects for all the parts that should be included in the query. For example: parts=["mesh","field",8] will include the parts named mesh, field, and part number 8 in the query.

The variables keyword variable is optional. If present, varlist should be a Python list variable that may include any mixture of string names, variable numbers or variable objects for all the variables that should be included in the query. For example: variables=["velocity","pressure",2] will include output for the variables named velocity, pressure and variable number 2 in the query.

The time keyword variable is optional. If not present, the query will be for the current time value in EnSight. The caller can also specify a specific time value using this keyword.

The return value is a list of output lists. One list for each input point. If no variables are specified, the query will be about the mesh structure and the list for each point will appear as:

[part_number, structuredpart_flag, closest_node, element_id]

The values are the part number the point was found in, a flag that is non-zero if the part is structured, the node id of the node closest to the point and the element id of the element that contains the point.

If a list of variables is specified, the returned value will be a list of lists, one for each variable. If the input variables were "pressure" and "velocity" (a scalar and a vector), the output (per point) would be:

[ [pressure_value], [velocity_x, velocity_y, velocity_z] ]

value = ensight.query_nodes(nodelist [,parts=partlist][,variables=varlist][,time=t])

This function is a basic variable and mesh query mechanism. It takes a list of node ids as input. An example would be: [500, 323] for two nodes. The function will perform a query at each node in the list.


Important:  Each of these nodal queries makes a round trip from the client to the server, one at a time. This is not intended to be used to query large numbers of nodes and will be extremely slow for large numbers of nodes. Use EnSight python for controlling EnSight, not for replacing the EnSight server.


The parts keyword variable is optional. If not present, the currently selected parts will be used. The parts keyword can be set to the string "all" (for example, parts="all") to select all parts in the current case, otherwise, partlist should be a Python list variable may include any mixture of string names, part numbers or part objects for all the parts that should be included in the query. For example: parts=["mesh","field",8] will include the parts named mesh, field, and part number 8 in the query.

The variables keyword variable is optional. If present, varlist should be a Python list variable that may include any mixture of string names, variable numbers or variable objects for all the variables that should be included in the query. For example: variables=["velocity","pressure",2] will include output for the variables named velocity, pressure and variable number 2 in the query.

The "time" keyword variable is optional. If not present, the query will be for the current time value in EnSight. The caller can also specify a specific time value using this keyword.

The return value is a list of output lists. One list for each input node. If no variables are specified, the query will be about the mesh structure and the list for each node will appear as:

[part_number, structuredpart_flag, [node_x, node_y, node_z], [element_list]

The values are the part number the node was found in, a flag that is non-zero if the part is structured, the coordinates of the node and a list of elements that reference that node.

If a list of variables is specified, the returned value will be a list of lists, one for each variable. If the input variables were pressure and velocity (a scalar and a vector), the output (per node) would be:

[ [pressure_value], [velocity_x, velocity_y, velocity_z] ]

value = ensight.query_elems(elemlist [,parts=partlist][,variables=varlist][,time=t])

This function is a basic variable and mesh query mechanism. It takes a list of element ids as input. An example would be: [232, 4733] for two elements. The function will perform a query at each element in the list.

The parts keyword variable is optional. If not present, the currently selected parts will be used. The parts keyword can be set to the string all (for example, parts="all") to select all parts in the current case, otherwise, partlist should be a Python list variable may include any mixture of string names, part numbers or part objects for all the parts that should be included in the query. For example: parts=["mesh","field",8] will include the parts named mesh, field, and part number 8 in the query.

The variables keyword variable is optional. If present, varlist should be a Python list variable that may include any mixture of string names, variable numbers or variable objects for all the variables that should be included in the query. For example: variables=["velocity","pressure",2] will include output for the variables named velocity, pressure and variable number 2 in the query.

The time keyword variable is optional. If not present, the query will be for the current time value in EnSight. The caller can also specify a specific time value using this keyword.

The return value is a list of output lists. One list for each input element. If no variables are specified, the query will be about the mesh structure and the list for each element will appear as:

[part_number, structuredpart_flag, element_type, failed_flag, [element_ijk_list], [node_list], [neighbor_element_list]]

The values are the part number the element was found in, a flag that is non-zero if the part is structured, the type of the element, a flag that is non-zero if the element is currently failed, a list of ijk bounds for the element (if the part is structured), a list of the nodes this element references and a list of the elements that neighbor this element.

If a list of variables is specified, the returned value will be a list of lists, one for each variable. If the input variables were pressure and velocity (a scalar and a vector), the output (per element) would be:

[ [pressure_value], [velocity_x, velocity_y, velocity_z] ]

value = ensight.query_trace_paths([parts=partlist][,variables=varlist])

This function allows the user to directly query the points that make up particle traces. The output is similar to the output generated by the test: trace_dump command, except that it is returned as a Python variable insted of a text file on disk. The function takes a list of particle trace objects as input, along with an optional list of variable names.

The parts keyword variable is optional. If not present, the currently selected parts will be used. The parts keyword can be set to the string all (for example, parts="all") to select all parts in the current case, otherwise, partlist should be a Python list variable may include any mixture of string names, part numbers or part objects for all the parts that should be included in the query. For example: parts=["mesh","field",8] will include the parts named mesh, field, and part number 8 in the query.

The variables keyword variable is optional. If present, varlist should be a Python list variable that may include any mixture of string names, variable numbers or variable objects for all the variables that should be included in the query. For example: variables=["velocity", "pressure", 2] will include output for the variables named velocity, pressure and variable number 2 in the query.


Note:  In order to get a valid return for a given variable, it must be active, and have been activated prior to the creation of the trace.


The return value is a list of output lists. One list for each input part. The list for each part will contain one list for every trace in the part. If no variables are specified, the list for each trace will contain information about the temporal and spatial location of each point on the trace in the form:

[x,y,z,t]

The time value t is the resident time for the trace.

If a list of variables is specified, the returned value will be a list per part of lists per trace of lists, one for each variable. If the input variables were pressure and velocity (a scalar and a vector), the output (per point on a trace) would be:

[ [pressure_value], [velocity_x, velocity_y, velocity_z]]

Example 8.2: In the Case of Two Parts, Each with 3 Traces of 4 Points Each and the Variable Keyword Specifying a Vector and a Scalar Variable, the Full Output Would Be

[

#part 1

[

#trace 1

[[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]]],

#trace 2

[[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]]],

#trace 3

[[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]],[[vx,vy,vz],[s]]]

],

#part 2

[...]

]


ensight.query_parts([parts=partlist][,client=client][,variables=varlist])

This method returns basic information about parts as a Python list. The parts keyword variable is optional. If not present, the currently selected parts will be used. The parts keyword can be set to the string all (for example, parts="all") to select all parts in the current case, otherwise, partlist should be a Python list variable may include any mixture of string names, part numbers or part objects for all the parts that should be included in the query. For example: parts=["mesh","field",8] will include the parts named mesh, field, and part number 8 in the query.

The variables keyword variable is optional. If present, varlist should be a Python list variable that may include any mixture of string names, variable numbers or variable objects for all the variables that should be included in the query. For example: variables=["velocity", "pressure", 2] will include output for the variables named velocity, pressure and variable number 2 in the query.

The return value is a list of output lists, one list for each selected part. The list for each part can have one of three structures, depending on the setting of the client keyword and the presence of the variables keyword. If the variables keyword is present, the return value is a list of lists, one per parts. Each list has the following structure:

[partID, [vlist]]

The vlist list has one value for each variable being queried. The value is 1 if the variable exists, is active and has some defined values for the given part. The value is -1 if the variable not active or not defined for the given part. The value -2 is returned if the part does not contain the variable or the variable is not defined on the part, or the part has no nodes/elements at the current timestep. The value -3 can be returned if the part is a client part (vector arrows, contour lines, etc) which never has variables defined on it. Other values are returned for invalid input parameters.

By default, the client keyword is 0 and results in a server query, much like the QueryShow InformationPart menu selection. Client side parts (for example, groups, pathlines, vector arrows) will not be included in this output. If the client keyword is set to the value 1, the query will be performed on the client. This is a much faster query and it includes all parts, but it returns less detailed information than the server query.

In the server query case (client=0), the list for each part has the following structure:

[partID, part_type, [x0,y0,z0], [x1,y1,z1], num_nodes, elemlist, is_selected, "partname", is_structured, ijkbounds, casenum, parentpartlist]

In the client query case (client=1), the list for each part has the following structure:

[partID, part_type, is_selected, "partname", is_structured, casenum, parentpartlist]

In both cases, the named fields are defined as:

partID = the part ID

part_type = the EnSight part type (for example, model, clip, etc) (int)

part_type will be one of the following values:

ensight.PART_MODEL, ensight.PART_CLIP_PLANE, ensight.PART_CONTOUR, ensight.PART_DISCRETE_PARTICLE, ensight.PART_FRAME, ensight.PART_ISO_SURFACE, ensight.PART_PARTICLE_TRACE, ensight.PART_PROFILE, ensight.PART_VECTOR_ARROW, ensight.PART_ELEVATED_SURFACE, ensight.PART_DEVELOPED_SURFACE, ensight.PART_MODEL_EXTRACT, ensight.PART_MODEL_CUT, ensight.PART_MODEL_BOUNDARY, ensight.PART_ISO_VOLUME, ensight.PART_BUILT_UP, ensight.PART_TENSOR_GLYPH, ensight.PART_FX_VORTEX_CORE, ensight.PART_FX_SHOCK, ensight.PART_FX_SEP_ATT, ensight.PART_MATERIAL_INTERFACE, ensight.PART_POINT, ensight.PART_AXI_SYMMETRIC, ensight.PART_MODEL_MERGE, ensight.PART_MULT

x0,y0,z0 = the part minimum x,y,z coords

x1,y1, z1 = the part maximum x,y,z coords

num_nodes = the number of nodes in the part

elemlist = a list of element types and the number of elements each type. For each element type in the part, there is a two element list in elemlist of the form: ['elemtype', num], that defines the number of elements of the specified type. elemtypes as text strings like Tria3 or Hexa8.

is_selected = an integer that is non-zero if the part is currently selected

partname = the name of the part as a string

is_structured = an integer that is non-zero if the part is structured. If non-zero, the ijkbounds list will be present.

ijkbounds = this list is only present if the part is structured. It consists of three, three element lists and has the form: [ [i_min, i_max, i_step, i_limit], [j_min, j_max, j_step, j_limit], [k_min, k_max, k_step, k_limit] ]. These are the current min, max and step size along the i, j and k axis for the structured part as well as the maximum (limit) of the individual axis bounds.

casenum = the case number to which this part belongs

parentpartlist= a list of part numbers that are the parents to this part. This list may be empty. It will be non-empty for derived parts (for example, clips, contours, etc).

ensight.query_cases()

This method returns basic information about the current EnSight cases as a Python list. The returned list has the following format:

[current_case_number,[case1_num,"case1_name"],[case2_num,"case2_name"]...]

The first item is the current case number (zero based). There will be one subsequent item for each current case. Each of those items is a list containing the number for that case and its name.

err=ensight.query_xy_create(title,xtitle,ytitle,data[,segments=seg])

This function creates a new xy query in EnSight. It is similar to reading a query from an external file, except the data is passed from Python. title, xtitle and ytitle are strings that specify the textual labels for the curve, x and y axis. "data" is a list of lists that takes the form:

[[x0,y0],[x1,y1],[x2,y2],...]

That is a list of two element lists which contain two float values each that are interpreted as an X,Y point in space. By default, the data is plotted as a connected line. The optional segments=seg keyword allows the caller to specify a seg variable which is a list of integers. Each integer is the length of a connected line of points. For example: [10,24,8] specifies that the first 10 points should be connected as a polyline, the next 24 as separate polyline and the remaining 8 as a separate polyline. The sum of the seg list integers must be the same as the number of points in the "data" list. A return value of 0 means the creation was successful, -1 means there were issues in the format of the input arguments, -2 suggests an out of memory condition and -3 means that the query was created, but that some values in the data list were missing (and set to 0.0).

ensight.qtparent()

This method returns None on X11 platform and a QWidget object under Windows. It is used in conjunction with ensight.reparent() to ensure that Python Qt windows can interact properly with the existing EnSight windows.

ensight.version([element])

Returns information about EnSight

Prior to version 2019 R1, the standard way of using this function was to call ensight.version() with no arguments and using the default data returned (described below). Since 2019 R1, the recommended method is to pass an element argument to ensight.version(), requesting the specific piece of information desired. In a future release, the legacy method of calling ensight.version() with no argument will be deprecated; an element argument will be required.

If no element argument is specified, the function returns a list containing 10 items:
  1. A version string in the legacy format xx.x.x(a). For example, 19.4.0(a)

  2. The license type as a string. For example, Enterprise, Standard, etc.

  3. The architecture of the client machine. For example, linux_2.6_64, win64

  4. The base installation directory

  5. The server version if one is running, otherwise None.

  6. The SOS version if one is running, otherwise None.

  7. A user and license dictionary (see below).

  8. major version string

  9. GUI type (only Qt)

  10. Apex release number.

The contents of the user and license dictionary will vary depending on the type of license manager. At the very least, the dictionary will contain an lmtype key, whose value will be ANSYS, SLiM, or FSI indicating the license manager type.

If the license manager is Ansys, the user and license dictionary will contain the following items:

  • keypath:ANSYS

  • host: The hostname of the client machine

  • customer: The Siebel customer number

  • username: The current user name

  • lmtype: Ansys

If the license manager is SLiM or FSI, the user and license dictionary will contain the following items:

  • host: The hostname of the client machine

  • ip: The IP address of the client machine

  • customer: Customer ID

  • username: The current user name

  • contact: The contact name from the license

  • company: The company name from the license

  • expdate: The license expiration date string

  • slimversion: The version number of the SLiM license manager

  • keypath: The location of the license information or server

  • hostid: A list of host IDs from the license manager

  • lmtype:SLiM

An example of such a list is:

['19.2.0(a)', 'Standard', 'win64', 'C:\\Program Files\\ANSYS Inc\\v194\\CEI', '19.2.0(a)', None, {'customer': '12345678', 'username': 'yourid', 'host': 'MACHINENAME', 'keypath': 'ANSYS', 'lmtype': 'ANSYS'}, '194', 'Qt', '194']

If a string is passed as the element argument, a particular element of version information is returned, corresponding to the following map:

  • version-full: The release number returned as a string. For example, 2019 R2

  • numeric: The release number returned as a list containing year, minor version, patch, and beta string returned as a Python list. For example, [2019, 2, 0, ‘’]

  • year: The year portion of the release number. Returned as an integer. For example, 2019

  • rel: The minor release number. Returned as an integer. For example, 2

  • patch: The patch number. Returned as an integer. For example, 0

  • beta: If the release was built as a beta, the beta string. Otherwise, an empty string.

  • ip: The IP address of the client machine.

  • product: The product name. For example, EnSight, EnVision, etc.

  • mode, license, or flavor: The license name. For example, Enterprise, Standard, etc.

  • company: The company name from the license. Can be an empty string if none is available.

  • customer: The customer name or id from the license returned as a string. Can be an empty string if none is available.

  • arch: The architecture of the client machine. For examplelinux_2.6_64, win64

  • CEI_HOME or home: The base installation directory as a string. For example, 'C:\\Program Files\\ANSYS Inc\\v194\\CEI'. The string will be formatted in a platform-specific way, with a drive letter and backslashes on Windows and forward slashes on Linux and macOS.

  • lmtype: The license manager type. One of ANSYS, SLiM, or FSI.

  • Slimversion: The version number of the SLiM license manager. None if the SLiM license manager is not used.

  • keypath: The location of the license file or server if the SLiM license manager is used. None otherwise.

  • username: The current user name

  • hostname: The host name of the client machine.

  • haveServer: A Python boolean indicating whether an EnSight server is currently running.

  • haveSOS: A Python boolean indicating whether an EnSight Server of Servers is currently running.

  • suffix: A three-character numeric string that serves as a short version number. For example, "194". This is frequently used when naming directories.

If an element string is given that is not supported, a ValueError Python exception is thrown.

ensight.checkabort([throw_exception])

In the EnSight Python editor, there is an option to set an abort flag. When this method is called, two things happen. First, all the pending graphical user interface events are processed. Second, if the user has selected the abort menu option, this method resets the abort state and returns a non-zero integer. If the abort menu has not been selected, this method returns the value 0. If throw exception is passed as an argument and is non-zero, if the function would return a non-zero value, it will instead throw a Python exception.

ensight.batch()

This method returns a non-zero integer if the EnSight client is running in batch mode.

ensight.exit()

This method causes EnSight to shut down the current EnSight session.

The Python Native Command Language Interface

As described in the previous section, the ensight.sendmesg() function can be used to execute command language from Python. The command language takes the form of a Python string or list of strings. There exists a collection of modules that implement a more natural Python (native) interface to the command language. These modules follow the form of the EnSight command language syntax. All command language commands have the fundamental form:

category: command <args>

For example:

view_transf: rotate 9.657229e+000 2.282249e+001 0.000000e+000

has a category of 'view_transf', a command of rotate and arguments of 9.657229e+000 2.282249e+001 0.000000e+000. The native command language interface maps the category and command names to modules under the 'ensight' module. For example, the above command is equivalent to the following line of Python code:

ensight.view_transf.rotate('9.657229e+000 2.282249e+001 0.000000e+000')

Additionally, the native interface will try to map data types to <args> strings. So the following lines of Python code are all equivalent:

ensight.view_transf.rotate(9.657229e+000,2.282249e+001,0.000000e+000)

ensight.view_transf.rotate([9.657229,2.282249e+01,0])

a=[9.657229,2.282249e+01,0]

ensight.view_transf.rotate(a)

The use of Python native variables makes this interface much more flexible for complex scripting.

The native interface handles the select_begin/select_end commands very differently. The command language includes structures like:

part: select_begin

1 2 3 4 5 6 7 8

part: select_end

part: select_byname_begin

(CASE:Case 1)Block ID 7 - HEX" "(CASE:Case 1)Block ID 8 - HEX

(CASE:Case 1)Block ID 9 - HEX" "(CASE:Case 1)Block ID 10 - HEX

(CASE:Case 1)Block ID 11 - HEX" "(CASE:Case 1)Block ID 1 - HEX

part: select_byname_end

The native Python interface is aware of the list nature of the select_begin/select_end commands and maps them to a single command (the select_begin). The above lines translate to two lines of Python:

ensight.part.select_begin(1,2,3,4,5,6,7,8)

ensight.part.select_byname_begin("(CASE:Case 1)Block ID 7 - HEX","(CASE:Case 1)Block ID 8 - HEX","(CASE:Case 1)Block ID 9 - HEX","(CASE:Case 1)Block ID 10 - HEX","(CASE:Case 1)Block ID 11 - HEX","(CASE:Case 1)Block ID 1 - HEX")

The *_end functions are not necessary. Additionally, a list-based syntax is also supported, so the following three lines are also equivalent:

ensight.part.select_begin([1,2,3,4,5,6,7,8])

list = ["(CASE:Case 1)Block ID 7 - HEX",

"(CASE:Case 1)Block ID 8 - HEX",

"(CASE:Case 1)Block ID 9 - HEX",

"(CASE:Case 1)Block ID 10 - HEX",

"(CASE:Case 1)Block ID 11 - HEX",

"(CASE:Case 1)Block ID 1 - HEX"]

ensight.part.select_byname_begin(list)

In all cases where the command language uses a *_begin/*_end syntax with a collection of items (numerical or strings), a Python command structure similar to the above may be used.

Conversion of Command Language Scripts to the Native Interface

In previous versions of EnSight, functions were provided to convert selections of command language to ensight.sendmesg() format. With the native interface, these have been replaced with two menu options in the EnSight Python script editor. Under the Edit menu, there is an option Convert selection to sendmesg() which converts the currently selected text in the editor into the ensight.sendmesg() form. More importantly, there is a Convert selection to native Python option. This function will convert command language to the native interface described here. One can convert a .enc file by loading it into the script editor window, selecting all of the text and converting it to native Python. The result can be saved as a .py file. An example of the conversion results would be:

VERSION 8.26
part: select_default
part: modify_begin
part: elt_representation 3D_feature_2D_full
part: modify_end
data: binary_files_are big_endian
data: format case
data: shift_time 1.000000 0.000000 0.000000
data: replace c:/Program Files/CEI/ensight102/data/cube/cube.case
view_transf: rotate -6.277198e+001 6.945956e-001 0.000000e+000
part: select_all
clip: begin
clip: value MID-RANGE
clip: domain intersect
clip: tool xyz
clip: end
clip: create
part: select_begin
2
part: select_end
view_transf: rotate 1.904619e+001 3.095920e+001 0.000000e+000
part: modify_begin
clip: value -0.425000
clip: tool xyz
part: modify_end
view: hidden_surface ON
variables: activate temperature
part: select_all
part: modify_begin
part: colorby_palette temperature
part: modify_end

Translates into the following native Python code:

ensight.sendmesgoptions(version=8.26)
ensight.part.select_default()
ensight.part.modify_begin()
ensight.part.elt_representation("3D_feature_2D_full")
ensight.part.modify_end()
ensight.data.binary_files_are("big_endian")
ensight.data.format("case")
ensight.data.shift_time(1.000000,0.000000,0.000000)
ensight.data.replace("c:/Program Files/CEI/ensight102/data/cube/cube.case")
ensight.view_transf.rotate(-6.277198e+001,6.945956e-001,0.000000e+000)
ensight.part.select_all()
ensight.clip.begin()
ensight.clip.value("MID-RANGE")
ensight.clip.domain("intersect")
ensight.clip.tool("xyz")
ensight.clip.end()
ensight.clip.create()
ensight.part.select_begin(2)
ensight.view_transf.rotate(1.904619e+001,3.095920e+001,0.000000e+000)
ensight.part.modify_begin()
ensight.clip.value(-0.425000)
ensight.clip.tool("xyz")
ensight.part.modify_end()
ensight.view.hidden_surface("ON")
ensight.variables.activate("temperature")
ensight.part.select_all()
ensight.part.modify_begin()
ensight.part.colorby_palette("temperature")
ensight.part.modify_end()
ensight.sendmesgoptions(version=0)

This language conversion is actually performed by the class Cmd2Py in the Python module: cei.cmd2py. A quick study of the cmd2py.py file will give an overview of the conversion process and what is and what is not handled by the conversion. Some command language cannot be converted automatically. Files that include things like command language loops cannot be converted automatically and the conversion system will insert comments detailing the failures. Examples that use other command language features that cannot be directly translated (for example, $ variables) will be converted to ensight.sendmesg() formatted lines as a fallback. In most cases, users are better off converting such sections of code into native Python in any case. A command line program: cmd2py is also provided to aid in the conversion of files outside of EnSight.

Usage Notes on the Native Python Interface

The native interface has the same limitations listed in Limitations of the EnSight Python Interface. In general, all of the command language is supported with a few exceptions.

One exception is the test: commands. These commands are not supported by the native interface (i.e. there is no ensight.test module). They can of course be issued using the ensight.sendmesg("test:...") interface.

There are a number of commands in the EnSight command language that are not valid Python names. A few examples include:

function: #_of_levels 5

annotation: 3d_label_size 10.0

command: print "hello"

viewport: raise

The reasons a name might be invalid include:

  1. name includes an invalid character (for example, "#")

  2. name begins with a digit (for example, "1")

  3. name is a Python reserved word (for example, "raise")

These are transformed using the following rules:

  1. "#" characters are replaced with the text number

  2. names that start with a digit are prefixed with an _

  3. names that are the same as a Python reserved word are prefixed with an _

The previous examples become:

ensight.function.number_of_levels(5)

ensight.annotation._3d_label_size(10.0)

ensight.command.print("hello")

ensight.viewport._raise()

There are a few obsolete EnSight command language functions that are not supported. One example would be:

part: symmetry_1_1_-1

Such functions can still be executed using ensight.sendmesg().

The native interface methods do not include the exception, record, display or version keywords like ensight.sendmesg(). However, they do honor the values set by ensight.sendmesgoptions(). That function can be used to cause the code that uses the native interface do be executed under the particular rules of a specific command language version or to throw exceptions on errors for instance.

EnSight Python Events

EnSight has a mechanism to execute Python code when various events occur in the main program. The module provides methods to add a callback and remove one. Each callback consists of a Python object, the name of a method on the object and a reason to be called back. An example Python class that registers itself for one rendering callback and then removes itself would be:

class cb_class:
    def register(self):
        self.ID = ensight.addcallback(self,"callback",ensight.ENS_EVENT_PRERENDER) 
    def callback(self,value):
        print("Called back from EnSight {}".format(value)) 
        ensight.removecallback(self.ID)
    example = cb_class()
    example.register()

Note:  Be aware that callback in the addcallback() method specifies the name of the function in the object to call. The value in the callback value argument vary depending on the specific event it is tied to, but it will always be a tuple that starts with the original event name passed in addcallback(). Another example, using the ENS_EVENT_PYTHON interface might be:

class py_cb_class:
    def   init  (self):
        self.filter = ensight.query(ensight.UNIQUE_ID)
        self.ID1 = ensight.addcallback(self,"fil_cb",ensight.ENS_EVENT_PYTHON,self.filter) 
        self.ID2 = ensight.addcallback(self,"def_cb",ensight.ENS_EVENT_PYTHON)
    def fil_cb(self,value):
        print("Filtered callback {} {}".format(self.filter, value)) 
        return 0
    def def_cb(self,value):
        print("Default callback {}".format(value)) 
        return 0
    def test(self):
        print("immediate,filtered: {}".format(ensight.sendevent(["hello"],filter=self.filter)))) 
        print("deferred: {}".format(ensight.sendevent(["goodbye"],deferred=1)))
example = py_cb_class()
example.test()

In this example, take careful note of the position and order of the generated output to see the effects of deferred callbacks.


EnSight Python Code Methods

ID = ensight.addcallback(object,"methodname",event_type[,timeout|filter])

This method registers the specified method name will be called on the passed object when the specified event_type occurs in EnSight. The function returns an ID number that can be passed to removecallback() to unregister the callback.

Currently defined values for event_type:

ensight.ENS_EVENT_ALL

The method will be called for all EnSight events. The callback function value will reflect the actual event type for which the callback was invoked.

ensight.ENS_EVENT_QUIT

EnSight is about to exit.

ensight.ENS_EVENT_SOLUTION_TIME

The current solution time has changed. The new time is passed as the value.

ensight.ENS_EVENT_NEW_TIME

The number of time steps has changed. The new time is passed as the value. This event is triggered due to simulation monitoring updates. This is an topic discussed in Load Transient Data.

ensight.ENS_EVENT_POSTRENDER

EnSight has just redrawn its current displays.

ensight.ENS_EVENT_PRECOMMAND

EnSight is about to execute the command language string passed as the value.

ensight.ENS_EVENT_POSTCOMMAND

EnSight has just executed the command language string passed as the value.

ensight.ENS_EVENT_TIMEOUT

A periodic time has occurred (see below).

ensight.ENS_EVENT_PARTSELECT

The current part selection has changed to the tuple of part numbers passed as value.

ensight.ENS_EVENT_PART

A part has either been created or destroyed. A value of 0 is passed on construction and 1 is passed on destruction. A value of 3 is passed when a part is renamed.

ensight.ENS_EVENT_CASE

A case has either been created, renamed, made current or destroyed. A value of 0 is passed on construction, 1 is passed on destruction, 2 is passed if the current case is made current and 3 is passed if a case is renamed.

ensight.ENS_EVENT_QUERY

A query in ensight has been created, destroyed or updated. Two values are passed. The first selects the type of the query. If the first value is: ensight.ENS_EVENT_QUERY_PROBE, the second value will be 0 and the current probe information has been updated. If the first value is: ensight.ENS_EVENT_QUERY_DATA the value can be 0 if a query has been created or 1 if it has been destroyed.

ensight.ENS_EVENT_VARIABLE

A variable has either been created/activated or destroyed/deactivated. A value of 0 is passed on construction and 1 is passed on destruction.

Special Event Types:

These events come from different sources and the callback functions may have slightly different behavior from the basic event types.

Python events:

ensight.ENS_EVENT_PYTHON

This event allows multiple Python objects running inside of the EnSight Python interpreter to pass information to each other. A callback function that is associated with this event type will be passed a Python list as its value (see: the method ensight.sendevent()). The return value of this callback function is important. If it has the integer value 1, no additional ENS_EVENT_PYTHON callbacks will be called with the value. If the callback returns the value 0, any remaining ENS_EVENT_PYTHON callbacks will also be called with the same value. When this event is specified, the optional filter parameter to the ensight.addcallback() is used. The parameter registers a tag with the callback that specifies that only the callbacks generated by a sendevent() call with that same tag be called. By default, the filter values are set to zero in both functions which results in a broadcast of the python list to all callbacks. The application can specify a unique 'tag' number to send private messages. See ensight.sendevent() for more details.

Low Level CVF (device) events:

EnSight's rendering windows are based on a framework called CVF. This framework provides an abstraction for all user input events. These event types give a Python callback the opportunity to see these low-level device events. It also gives the callback the opportunity to suppress the handling of these events by the normal EnSight handlers. This can be useful for applications that decide they want specify control over user input in the graphics windows or want to override the default EnSight behavior for types of interaction. If the callback for one of these events returns the integer value 1, the event will not be passed on to EnSight. A return value of 0 will allow normal EnSight event processing to occur.

ensight.ENS_EVENT_MOUSE_BUTTON_DOWN

The passed value will be the list: [ENS_EVENT_MOUSE_BUTTON_DOWN, button, buttonstate, modifiers, x, y]

ensight.ENS_EVENT_MOUSE_BUTTON_UP

The passed value will be the list: [ENS_EVENT_MOUSE_BUTTON_UP, button, buttonstate, modifiers, x, y]

ensight.ENS_EVENT_MOUSE_DOUBLE_CLICK

The passed value will be the list: [ENS_EVENT_MOUSE_DOUBLE_CLICK, button, buttonstate, modifiers, x, y]

ensight.ENS_EVENT_MOUSE_MOTION

The passed value will be the list: [ENS_EVENT_MOUSE_MOTION, buttonstate, modifiers, x, y]

ensight.ENS_EVENT_WHEEL_MOTION

The passed value will be the list: [ENS_EVENT_WHEEL_MOTION, val, dir, modifiers, x, y]

ensight.ENS_EVENT_KEY_DOWN

The passed value will be the list: [ENS_EVENT_KEY_DOWN, key, modifiers, x, y]

ensight.ENS_EVENT_KEY_UP

The passed value will be the list: [ENS_EVENT_KEY_UP, key, modifiers, x, y]

ensight.ENS_EVENT_6D_MOTION

The passed value will be the list: [ENS_EVENT_6D_MOTION, tracker]

ensight.ENS_EVENT_6D_BUTTON_DOWN

The passed value will be the list: [ENS_EVENT_6D_BUTTON_DOWN, tracker]

ensight.ENS_EVENT_6D_BUTTON_UP

The passed value will be the list: [ENS_EVENT_6D_BUTTON_UP, tracker]

ensight.ENS_EVENT_6D_VALUATOR

The passed value will be the list: [ENS_EVENT_6D_VALUATOR, valuator, value]

ensight.ENS_EVENT_DRAWABLE_RESIZ

The passed value will be the list: [ENS_EVENT_DRAWABLE_RESIZE]

ensight.ENS_EVENT_DRAWABLE_EXPOSE

The passed value will be the list: [ENS_EVENT_DRAWABLE_EXPOSE

ensight.ENS_EVENT_DRAWABLE_SHOW

The passed value will be the list: [ENS_EVENT_DRAWABLE_SHOW]

ensight.ENS_EVENT_DRAWABLE_HIDE

The passed value will be the list: [ENS_EVENT_DRAWABLE_HIDE]

ensight.ENS_EVENT_DRAWABLE_FOCUSIN

The passed value will be the list: [ENS_EVENT_DRAWABLE_FOCUSIN]

ensight.ENS_EVENT_DRAWABLE_FOCUSOUT

The passed value will be the list: [ENS_EVENT_DRAWABLE_FOCUSOUT]

ensight.ENS_EVENT_DRAWABLE_ENTER

The passed value will be the list: [ENS_EVENT_DRAWABLE_ENTER]

ensight.ENS_EVENT_DRAWABLE_LEAVE

The passed value will be the list: [ENS_EVENT_DRAWABLE_LEAVE]

ensight.ENS_EVENT_DRAWABLE_SAVE

The passed value will be the list: [ENS_EVENT_DRAWABLE_SAVE]

ensight.ENS_EVENT_DRAWABLE_RESTORE

The passed value will be the list: [ENS_EVENT_DRAWABLE_RESTORE]

The x and y values are the location of the cursor at the time of the event. Generally, the button value will be one of (ensight.ENS_BUTTON_LEFT, ensight.ENS_BUTTON_RIGHT, ensight.ENS_BUTTON_MIDDLE, ensight.ENS_BUTTON_WHEEL), while buttonstate is the arithmetic or of these values together for the current state of all the buttons. The modifiers values will be the arithmetic or of none or some of the following values: ensight.MODIFIER_CTRL , ensight.MODIFIER_SHIFT , ensight.MODIFIER_ALT .

Timer events

ensight.ENS_EVENT_TIMEOUT

This is a special case in that it requires an extra timeout argument to addcallback(). Registering for this event type schedules a periodic callback to the Python code from EnSight every timeout seconds (timeout is a float). ENS_EVENT_ALL callbacks are not called for ENS_EVENT_TIMEOUT events.

err = ensight.removecallback(ID)

This method removes the previously registered callback function.

suppressed = ensight.sendevent( python_list [,filter=f][,deferred=d] )

This method works in conjunction with ensight.ENS_EVENT_PYTHON. When this function is called from the EnSight Python interpreter, all of the callback functions that were associated with ENS_EVENT_PYTHON are called with the Python list object passed to this function as a parameter. If a callback returns the value of 1, then the list is not passed to any additional callback functions of this type and sendevent() returns 1. This mechanism is used to allow multiple objects running within the EnSight Python interpreter to communicate with each other and pass data, messages, etc back and forth within EnSight. By default, this is a synchronous call, so callback functions that themselves call sendevent() must take care to ensure that their callback function is reentrant. The user may also specify the deferred= keyword to make the callback asynchronous. If deferred is set to 1, this function will return immediately, but will queue up the callback for later execution. At the next point where EnSight becomes idle the callbacks will be executed. This can be very useful in breaking circular callback loops. By default, the python list object is sent to all methods registered for the ENS_EVENT_PYTHON callback. The filter= keyword can be used to select a specific subset of registered methods be called instead of all of them. The filter keyword works in conjunction with the filter parameter to ensight.addcallback() to create private communications channels. The ensight.query(ensight.UNIQUE_ID) call can be used to generate guaranteed unique numbers that can be used for filter values at runtime to avoid colliding with other applets which may also use this mechanism.