Core: ENS_GLOBALS

Object API ››
Parent Previous Next

Core: ENS_GLOBALS

ensight.objs.core object

The ENS_GLOBALS object is central to the Python Object API. This is the ensight “global” object, the one and only instance of the ‘ENS_GLOBALS’ class. Check the attributes on this object. They include lists of parts, cases, variables, annotations, etc.

Attributes:

Methods:

For example, for a variable with the ENS_UNITS_LABEL and version 2.0 of the schema specified, the command:

ensight.objs.core.get_units(var)

returns: 'm^2 s^-2'

ensight.objs.core.get_units(var, format=1, prefix='[', suffix=']')

returns: '[m2/s2]'  encoded in the platforms native 8bit Unicode scheme.

ensight.objs.core.get_units(var, format=2, prefix='[', suffix=']')

returns: '[m<uc=00b2>/s<uc=00b2>]'


Starting from EnSight R 20.1, utf8=0 and utf8=1 will return the same unicode string object (in Python 3 all strings are unicode). You can set utf8=2 to get the corresponding byte object. So,

ensight.objs.core.get_units(var)

returns: 'm^2 s^-2'

ensight.objs.core.get_units(var, format=1, utf8=1)

returns: "m2/s2 "

ensight.objs.core.get_units(var, format=1, utf8=2)

returns: "b'm\xc2\xb2/s\xc2\xb2''

It is also legal to pass a dimensions string to get_units() instead of a variable object.  For example ensight.objs.core.get_units("LL/SS",...) will generate the same output as the above examples, except that it may not return specific units labels associated with the variable.

This API can generate labels from DIMS and SYSTEM values if no explicit label string has been specified for the variable object.

idx = 0

while True:

    try:

        print(ensight.objs.core.unit_system(enumerate=idx))

    except:

        break

    idx += 1


Which looks like this:

('USER', 'User defined units', False, {'A': '', 'D': '', 'I': '', 'K': '', 'M': '', 'L': '', 'Q': '', 'T': ''})

('SI', 'Metric SI', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'K', 'M': 'kg', 'L': 'm', 'Q': 'A', 'T': 's'})

('CGS', 'Metric CGS', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'g', 'L': 'cm', 'Q': 'A', 'T': 's'})

('BFT', 'US ft Consistent', False, {'A': 'slugmol', 'D': 'rad', 'I': 'cd', 'K': 'F', 'M': 'slug', 'L': 'ft', 'Q': 'A', 'T': 's'})

('BIN', 'US in Consistent', False, {'A': 'lbmmol', 'D': 'rad', 'I': 'cd', 'K': 'F', 'M': 'slinch', 'L': 'in', 'Q': 'A', 'T': 's'})

('MKS', 'Metric MKS', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'kg', 'L': 'm', 'Q': 'A', 'T': 's'})

('MPA', 'Metric MPA', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'tonne', 'L': 'mm', 'Q': 'mA', 'T': 's'})

('uMKS', 'Metric uMKS', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'kg', 'L': 'um', 'Q': 'pA', 'T': 's'})

('CGSK', 'Metric CGSK', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'K', 'M': 'g', 'L': 'cm', 'Q': 'A', 'T': 's'})

('NMM', 'Metric NMM', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'kg', 'L': 'mm', 'Q': 'mA', 'T': 's'})

('uMKSS', 'Metric uMKSS', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'kg', 'L': 'um', 'Q': 'mA', 'T': 's'})

('NMMDAT', 'Metric NMMDAT', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'decatonne', 'L': 'mm', 'Q': 'mA', 'T': 's'})

('NMMTON', 'Metric NMMTON', False, {'A': 'mol', 'D': 'rad', 'I': 'cd', 'K': 'C', 'M': 'tonne', 'L': 'mm', 'Q': 'mA', 'T': 's'})

('BFTS', 'US ft', False, {'A': 'lbmmol', 'D': 'rad', 'I': 'cd', 'K': 'F', 'M': 'lbm', 'L': 'ft', 'Q': 'A', 'T': 's'})

('BINS', 'US in', False, {'A': 'lbmmol', 'D': 'rad', 'I': 'cd', 'K': 'F', 'M': 'lbm', 'L': 'in', 'Q': 'A', 'T': 's'})

('USENG', 'US Engineering', False, {'A': 'lbmmol', 'D': 'rad', 'I': 'cd', 'K': 'R', 'M': 'lb', 'L': 'in', 'Q': 'A', 'T': 's'})

('Unknown', 'From first loaded case', False, {'A': '', 'D': '', 'I': '', 'K': '', 'M': '', 'L': '', 'Q': '', 'T': ''})


var_dims = ensight.objs.core.get_unit_dimensions(ensight.objs.core.VARIABLES['EleSize'][0])

(m, b) = ensight.objs.core.get_unit_conversion(ensight.objs.core.unit_system()[0], "BFT", var_dims)


returns: (35.31466672148858, 0.0)

In all cases, the return value will be a three value tuple of the current gRPC server status. The first value will be True or False depending on if the server is running or not.  The second value will be the port number the server is running on. The third value is the security string. The security string used when starting the new server will be taken from the security_string keyword.  If not present, the previous security_string will be used.

This method may throw exceptions on server start/stop errors.


There are a number of event types.  Each event type has an ID number and several required dictionary keys:

    CVF_MOUSE_BUTTON_DOWN = 100

    CVF_MOUSE_BUTTON_UP = 101

    CVF_MOUSE_DOUBLE_CLICK = 102


       dict(type={event type}, x={xposition}, y={yposition}, button={button that caused the event},

buttonstates={the state of all of the other mouse buttons}, modifiers={the current keyboard modifiers})


Simple left mouse down example:

 dict(type=100, x=200, y=200, button=1, buttonstate=1, modifiers=0)


    CVF_MOUSE_MOTION = 103


       dict(type={event type}, x={xposition}, y={yposition}, buttonstates={the state of all of the other mouse buttons},

modifiers={the current keyboard modifiers})


Simple mouse motion with the right button down with the shift key:

 dict(type=103, x=200, y=200, buttonstate=4, modifiers=2)


    CVF_WHEEL_MOTION = 150

    CVF_WHEEL_BEGIN = 151

    CVF_WHEEL_END = 152


       The mouse wheel consists of three events: begin, motion and end in that order.


       dict(type={event type}, value={change in value}, x={xposition}, y={yposition}, modifiers={the current keyboard modifiers})


Simple mouse wheel motion takes three events:

dict(type=151, x=200, y=200, modifiers=0)

dict(type=150, x=200, y=200, value=-120, modifiers=0)

dict(type=152, x=200, y=200, modifiers=0)


    CVF_KEY_DOWN = 200

    CVF_KEY_UP = 201


       dict(type={event type}, x={xposition}, y={yposition}, buttonstates={the state of all of the other mouse buttons},

modifiers={the current keyboard modifiers})


Simple key ('A') down with the control key down:

 dict(type=200, x=200, y=200, key=0x41, modifiers=1)


The keycodes for most keys match their ASCII codes.  Other keys (e.g. Function Keys) use the same lower 8bits as their Qt Keycodes, but or-ed with 0x1000.  For example, the 'End' key in Qt is 0x01000011 while the CVF keycode is 0x1011.


The button value masks are:

    CVF_BUTTON_NONE = 0

    CVF_BUTTON_LEFT = 1

    CVF_BUTTON_MIDDLE = 2

    CVF_BUTTON_RIGHT = 4

    CVF_BUTTON_WHEEL = 128


The keyboard modifier value masks are:

    CVF_MODIFIER_NONE = 0

    CVF_MODIFIER_CTRL = 1

    CVF_MODIFIER_SHIFT = 2

    CVF_MODIFIER_ALT = 4



find_objs() examples:

The ensight.objs.core.find_objs() method can be used in a large number of ways. Some common examples are illustrated here. Note also that: ensight.objs.core.find_objs(...,group=1).CHILDREN will return an ensobjlist interface to objects returned by find_objs().


import ensight
from ensight.objs import *

# find all PART objects in the current case
l = core.find_objs(core.CURRENTCASE,types=[ENS_PART],recurse=1)
# make a group from them...
c = core.create_group(l)

# find all non VISIBLE parts as a group object
g = core.find_objs(core.PARTS,filter={enums.VISIBLE: False},group=1)
# and make them all visible
g.setchildattr(enums.VISIBLE, True)

# find all the VISIBLE, CLIP parts currently selected
d = {enums.VISIBLE: True, enums.PARTTYPE: ensight.PART_CLIP_PLANE}
l = core.find_objs(core.selection(ENS_PART),filter=d)

# define a class with a custom __cmp__ method
class strstr():
    def __init__(self, value):
        self._v = value
    def __cmp__(self, other):
        if other.find(self._v) >= 0:
            return 0
        return 1

    def __eq__(self, other):

        return other.find(self._v) >= 0

    def __ne__(self, other):

        return other.find(self._v) < 0

    def __lt__(self, other):

        return False

    def __gt__(self, other):

        return False

    def __le__(self, other):

        return other.find(self._v) >= 0

    def __ge__(self, other):

        return other.find(self._v) >= 0

# find all parts in the current case that have "Block" in their DESCRIPTION

# Note the function defines both the Python 2 and Python 3 interfaces

# core.find_objs() will only use the __eq__() method, the others are there for completeness
d = {enums.DESCRIPTION: strstr("Block")}
l = core.find_objs(core.CURRENTCASE,filter=d,types=[ENS_PART],recurse=1)

# define a pure comparison case to see if a variable is valid for a case
class casevar():
    def __cmp__(self, other):
        if other[core.CURRENTCASE[0].CASENUMBER]:
            return 0
        return 1
    def __eq__(self, other):

        return other[core.CURRENTCASE[0].CASENUMBER]

    def __ne__(self, other):

        return not other[core.CURRENTCASE[0].CASENUMBER]

    def __lt__(self, other):

        return False

    def __gt__(self, other):

        return False

    def __le__(self, other):

        return other[core.CURRENTCASE[0].CASENUMBER]

    def __ge__(self, other):

        return other[core.CURRENTCASE[0].CASENUMBER]


# find active, scalar variables defined for the current case and make a group

# Note the function defines both the Python 2 and Python 3 interfaces
d = {enums.EXIST_CASE: casevar(), enums.ACTIVE: 1, enums.VARTYPE: enums.ENS_VAR_SCALAR}
g = core.find_objs(core.VARIABLES,filter=d,group=1)

# define a class that defines __cmp__ to be the "find" operation
# on a list
class multival():
    def __init__(self,lst):
        self._list = lst
    def __cmp__(self,other):
        if self._list.count(other):
            return 0
        return 1

    def __eq__(self, other):

        return self._list.count(other) > 0

    def __ne__(self, other):

        return self._list.count(other) <= 0

    def __gt__(self, other):

        return False

    def __lt__(self, other):

        return False

    def __ge__(self, other):

        return self._list.count(other) > 0

    def __le__(self, other):

        return self._list.count(other) > 0


# use it to find the parts with descriptions that are in a list
f = {enums.DESCRIPTION: multival(["engine","windshields"])}
parts = core.find_objs(core.PARTS,filter=f)


# Returns a list of selected parts 
# Resolves selected groups into parts 

def expand_children(inparts): 
    output = [] 
    for i in inparts: 
        lst = core.find_objs(core.PARTS,filter {enums.PARTNUMBER:i,enums.ISGROUP:True})
        if len(lst):
            for j in lst[0].SOURCES: 
                output.append(j.PARTNUMBER) 
        else:
            output.append(i)
    return output


Note: the “default” lists can be used to generate GUIs, etc without creating an actual item.