Object API

Previous Next

Object API

The object API was introduced in EnSight 9.0. This is largely an undocumented API and is subject to change without notice. The API forms many of the underpinnings of EnSight. The API directly exposes the core EnSight objects using a structured API. It provides for object introspection, "attribute/property"-based interfaces, a new deferred event mechanism and an atomic execution model.

At the core of the Object API is a common object interface.  All EnSight objects are represented by Python proxy objects. These objects have a standard interface documented here.  All EnSight objects are assigned a unique ID and the proxy uses this ID to find the underlying C++ object. Note: the lifetime of the proxy object does not match that of the EnSight object. It is possible for the EnSight object to be destroyed independently of the Python proxy.  When this happens, the Python interfaces will throw an error that the target C++ object no longer exists. A set of utility functions exist to manage the nature of the proxy objects. These are available in the ensight.objs module.

ensight.objs Module

The system is realized in the module: ensight.objs In that module are the class wrappers themselves (named as ‘ENS_CLASSNAME’), a module named ‘enums’, an object reference ‘core’ and several methods.

Class type objects

Models

Methods


Object type        Attribute        Description

ENS_PART        ENS_KIND        "Kind"

ENS_CASE        ENS_KIND        "Kind"

ENS_PART        ENS_DETAILS        "Details"

ENS_CASE        ENS_DETAILS        "Details"

ENS_PART        ENS_MATERIAL        "Material"

ENS_PART        DTA_BLOCK        "Block"

ENS_VAR        CFD_VAR        "CFD Type"

ENS_PART        ENS_UNITS_LABEL        "Units"

ENS_VAR        ENS_UNITS_LABEL        "Units"

ENS_VAR        FEA_VAR         "FEA Type"

 

Objects

Internal objects used in the representation for various attributes and system state.


ens_animobj - a periodic callback object designed for animation

 

ens_emitterobj - a particle trace emitter

a=ensight.objs.ens_emitterobj([type=t][repr=s])

Types:

ensight.objs.EMIT_CURSOR

ensight.objs.EMIT_LINE

ensight.objs.EMIT_PLANE

ensight.objs.EMIT_PART

ensight.objs.EMIT_FILE

Attributes:

TYPE - read only

ID - read only

CENTROID,POINT1 - 3 floats

POINT2 - 3 floats

POINT3 - 3 floats

POINT4 - 3 floats

NUM_POINTS - number of points (e.g. along a line)

NUM_POINTS_X - grid for a plane tool emitter

NUM_POINTS_Y - see above

PART - part object (1D?)

FILENAME - from a file

Methods:

a.fromtool(toolobj) - set the emitter values from a tool object

a.totool(toolobj) - set the tool object to the emitter object settings

 

infotree - used in the representation of attribute group trees

Notes

 One thing to note about events. If they are registered with the classname instead of an object, they will be called back for all objects of that class. Also, if the object is an ENS_PART or ENS_LPART, the event will be pushed up the parent-child hierarchy and any parent callbacks will be made.


Example code:

import ensight

from ensight.objs import *  

class example:

    def __init__(self):

        self.p = core.PARTS[0]

        self.id1 = addcallback(self.p,self,"cb1")

        self.id2 = addcallback(self.p,self,"cb2",attrs=[enums.VISIBLE])

        print("registered {} {}".format(self.id1, self.id2))

    def cb1(self,target,why):

        print("cb1: {} {} {}".format(target, why, enum_to_name(why)))

        return 0

    def cb2(self,target,why):

        print("cb2: {} {} {}".format(target, why, enum_to_name(why)))

        return 0

  foo = example()

  print "TEST1: both callbacks called"

foo.p.VISIBLE = 0

print("TEST2: only 'cb1' called")

foo.p.COLORBYRGB = [1.,1.,1.]


callbacks in the parent object will be invoked as well as those on the target child.