Python in .enc files

Parent Previous Next

Using Python in EnSight .enc Files

Simple One-line Python

EnSight allows for Python to be directly used in command language scripts. When the command language interpreter sees a line that begins with the string 'ensight.', it will pass the line (and only that single line) to the Python interpreter for execution.  This means that self-contained Python one line commands can often be directly embedded in command language.  For example, the line:


is legal in Python (.py) or in command language (.enc).  One caveat, if a command language file containing a line like this is executed from within a .py file, the Python interpreter will be re-entrant and fail.  In practice, this is not generally a problem.

Left Hand Expressions: 'enscl'

This does mean that it is difficult to use any Python code with a left hand side expression from command language. A special module was added to EnSight: 'enscl'.  This module begins as an empty module.  However, if the command language interpreter sees a line beginning with 'enscl.' it will also pass that line to the Python interpreter as well.  This means that an expression like:

enscl.FOO = ensight.objs.core.STEREO_SEPARATION + 2.0

is legal and will set the module member 'FOO' to the value of the expression. This can be exploited in various ways:

enscl.tmp = []
enscl.tmp.append( ensight.objs.core.PARTS.find( 1, ensight.objs.enums.PARTNUMBER )
enscl.tmp.append( ensight.objs.core.PARTS.find( 2, ensight.objs.enums.PARTNUMBER )
enscl.tmp.append( ensight.objs.core.PARTS.find( 3, ensight.objs.enums.PARTNUMBER )
ensight.objs.core.selection().addchild( enscl.tmp, replace=1)

is legal in both Python and command language and will set the current part selection to parts with part numbers 1, 2 and 3. Again, the Python must be representable as a single line of code for this to work and each line must begin with 'ensight.' or 'enscl.'.  By convention, programmers are suggested to use 'enscl.tmp' for storage of temporary values.  It is assumed that reuse of that member will not cause any problems for other portions of command language.

Macro Expansion: 'enscl'

Finally, command language has been extended to allow for the expansion of objects in the 'enscl' module as macros.  So, the following command language snippet is legal:

enscl.tmp = -1.660036e+001
view_transf: rotate 0.000000e+000 0.000000e+000 $enscl.tmp

The core knows how to properly expand float, int and string values.  All other values are converted using 'str()' internally.