smesh/doc/examples/grouping_elements_ex01.py

71 lines
1.9 KiB
Python
Raw Normal View History

2013-02-12 20:37:44 +06:00
# Create a Standalone Group
2022-04-11 18:28:01 +05:00
from mechanic import *
2013-02-12 20:37:44 +06:00
# Get ids of all faces with area > 100
2022-04-11 18:28:01 +05:00
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
2013-02-12 20:37:44 +06:00
anIds = mesh.GetIdsFromFilter(aFilter)
# create a group consisting of faces with area > 100
aGroup1 = mesh.MakeGroupByIds("Area > 100", SMESH.FACE, anIds)
2013-02-12 20:37:44 +06:00
# create a group that contains all nodes from the mesh
aGroup2 = mesh.CreateEmptyGroup(SMESH.NODE, "all nodes")
2013-02-12 20:37:44 +06:00
aGroup2.AddFrom(mesh.mesh)
# ====================================
# Various methods of the Group object
# ====================================
aGroup = mesh.CreateEmptyGroup(SMESH.NODE, "aGroup")
# set/get group name
aGroup.SetName( "new name" )
2017-03-20 17:27:30 +05:00
print("name", aGroup.GetName())
# get group type (type of entities in the group, SMESH.NODE in our case)
2017-03-20 17:27:30 +05:00
print("type", aGroup.GetType())
# get number of entities (nodes in our case) in the group
2017-03-20 17:27:30 +05:00
print("size", aGroup.Size())
# check of emptiness
2017-03-20 17:27:30 +05:00
print("is empty", aGroup.IsEmpty())
# check of presence of an entity in the group
aGroup.Add([1,2]) # Add() method is specific to the standalone group
2017-03-20 17:27:30 +05:00
print("contains node 2", aGroup.Contains(2))
# get an entity by index
2017-03-20 17:27:30 +05:00
print("1st node", aGroup.GetID(1))
# get all entities
2017-03-20 17:27:30 +05:00
print("all", aGroup.GetIDs())
# get number of nodes (actual for groups of elements)
2017-03-20 17:27:30 +05:00
print("nb nodes", aGroup.GetNumberOfNodes())
# get underlying nodes (actual for groups of elements)
2017-03-20 17:27:30 +05:00
print("nodes", aGroup.GetNodeIDs())
# set/get color
import SALOMEDS
aGroup.SetColor( SALOMEDS.Color(1.,1.,0.));
2017-03-20 17:27:30 +05:00
print("color", aGroup.GetColor())
# ----------------------------------------------------------------------------
# methods specific to the standalone group and not present in GroupOnGeometry
# and GroupOnFilter
# ----------------------------------------------------------------------------
# clear the group's contents
aGroup.Clear()
# add contents of other object (group, sub-mesh, filter)
aGroup.AddFrom( aGroup2 )
# removes entities
aGroup.Remove( [2,3,4] )