Groups: ENS_GROUP
There are three basic forms of ENS_GROUP objects. The first is encountered as part of the object tree rooted in the ENS_CASE objects. These objects are not marked as selections and can be returned as some an object’s PARENT. There are restrictions on the types of objects that can be added to these objects and they cannot move between cases. All such groups will have PARENTs. The second are the core selection objects. These can be accessed by core.selection() and are marked as selections. They cannot be destroyed and are owned by EnSight. They can only hold homogeneous objects based on the parameter passed to core.selection(). They are intimately tied to the native EnSight GUI and reflect widget selections. The final type are “user” selection groups. These are created with core.create_group() and can store non-homogeneous objects. These are owned by Python and can be destroyed at will. They are normally used to wrapper lists of objects to allow for more efficient get/set property operations.
Methods:
- foo.destroy([recurse=1]): destroy the specific group. By default all children are moved to the parent of the ENS_GROUP part. If the recurse keyword is set, all of the children (and their children) are destroyed.
- foo.setchildattr(attr,value): recursively execute setattr on all the ENS_PART objects in this case
- foo.setchildattrs(dict): recursively execute setattrs on all the ENS_PART objects in this case
- group = foo.creategroup(name): create a new group as a child of the group foo. The new group will have its description attribute set to the value of 'name'.
- foo.addchild(v|list[,replace=1][record=1][include_lpart=1]) (adds the passed object as a child of this object, removing it from its previous parent, if any). If replace=1 is specified, all existing children will be removed before the new child(ren) are added. If the group is an ENS_PART selection object, the record=1 keyword can be used to force the new part selection to be recorded in command language. Note: the include_lpart keyword was introduced in EnSight 10.0.2(I). If this keyword is set to 1 and an ENS_PART object is being added to a non-selection ENS_GROUP object, EnSight will check to see if the ENS_LPART object referenced by the part's LPARTPARENT attribute shares the same initial parent as the part itself. If it does, the ENS_LPART object will be added to the group along with the part. This feature was added to simplify some transitions from EnSight 9.x to 10.x groups.
Attributes:
- DESCRIPTION: the name of the group
- PARENT: the parent object of the group
- METADATA: user-defined metadata attached to this group
- CHILDREN: list of selected objects.
- SELECTIONS: boolean, true if it is a selection object
In EnSight 10.0, the ENS_GROUP object plays a much more important role in the GUI than it did in 9.x. This is outlined on the page EnSight 10.0 Groups.
In EnSight 10.0.2(h), the ENS_GROUP object was significantly updated. The most important addition is a 3D transformation that is applied to the children of this group when they are drawn. This is sort of like an EnSight 'frame', except that the transformations are hierarchical. The group object does three transformations: a rotation, a translation and a scale. These transformations are independent and applied in that order.
New attributes added in EnSight 10.0.2(h):
- TRANSLATION: [x,y,z] value added to the coordinates of the children of this group.
- ROTATION: [q0,q1,q2,q3,q4] a rotation matrix specified as a quaternion applied to the coordinates of the children of this group.
- SCALE: [sx,sy,sz] three anisotropic scaling values applied to the coordinates of the children of this group.
- COMPOSITE_MATRIX: ro the composite 4x4 transform matrix formed by combining MATRIX with the COMPOSITE_MATRIX attribute of any parent group to this group.
- MATRIX: ro the 4x4 transform matrix formed by the TRANSLATION, ROTATION and SCALE attributes from this group.
- POLYGON_OFFSET: boolean, if true, the children of this group are drawn with a slight shift in Z. If two identical parts are placed in a group where this value is true and in one where this value is false, the one where the group setting is false will be displayed in front of the one where the setting is true.
- PATHNAME: ro name of the group that includes its heirarchcial path. An example might be 'Case 1|New group' for a group at the top of case 1. This can be used to uniquely reference a group by name.
New methods added in EnSight 10.0.2(h):
- foo.transform([rots=l][,quat=l][,trans=l][,scale=l][,reset=r][,record=r]): this method allows for the three transformation attributes to be modified in an incremental (or absolute fashion). All of the parameters are optional. If 'reset=N' is specified, it will reset the specific attributes to their default values. The parameter is formed by oring the following: 1=rotation, 2=translation, 4=scale. If present, this keyword is processed before the others. 'rots= [nx,ny,nz,ang] ' applies a rotation over the axis defined by [nx,ny,nz] by the angle 'ang' specified in radians. 'quat=[q1,q2,q3,q4]' is similar to 'rots=', except the rotation is interpreted as a quaternion. 'trans= [tx,ty,tz] ' specifies that [tx,ty,tz] should be added to the current translation. 'scale= [sx,sy,sz] ' specifies that the current scale values should be multiplied by [sx,sy,sz]. If 'record=1' is specified, command language will be recorded for the operation.
- g = foo.create_group(name): create a new group as a child of this group with the given name as its' DESCRIPTION attribute.
ENS_GROUP - selection object
Selection objects are special ENS_GROUP objects that reflect the current selections in the EnSight GUI. These include ENS_PART and ENS_ANNOT objects. If the selection object is for the ENS_PART or ENS_VAR selection, the list of children can be part/var ids or the string names of the parts/vars to be added. Adding an object to one of these objects changes the current selection and removing one from this group unselects it.
- foo.removechild([child|childlist]): with no parameters, unselect all of the objects. Otherwise, one can pass a single object or a list of objects to remove (and unselect).
ENS_GROUP - other Python protocols
The ENS_GROUP (and ENS_CASE) objects implement portions of the Python sequence protocol. These include length, indexing, contains and iteration. An example based on selection objects:
for i in core.PARTS:
i.SELECTED = True
# Get selection object
sel = core.selection(ENS_PART)
# Note: sel is an ENS_GROUP object!
print "Number of objects = ",len(sel)
for i in sel:
print(" {}".format(i.DESCRIPTION))
# test for presence
print("Is the first part selected: {}".format(core.PARTS[0] in sel))