Salome HOME
[bos #40653][CEA] New mesh import export formats with meshio.
[modules/smesh.git] / doc / examples / grouping_elements_ex01.py
1 # Create a Standalone Group
2
3 from mechanic import *
4
5 # Get ids of all faces with area > 100 
6 aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
7
8 anIds = mesh.GetIdsFromFilter(aFilter) 
9
10 # create a group consisting of faces with area > 100
11 aGroup1 = mesh.MakeGroupByIds("Area > 100", SMESH.FACE, anIds)
12
13 # create a group that contains all nodes from the mesh
14 aGroup2 = mesh.CreateEmptyGroup(SMESH.NODE, "all nodes")
15 aGroup2.AddFrom(mesh.mesh)
16
17
18 # ====================================
19 # Various methods of the Group object
20 # ====================================
21
22 aGroup = mesh.CreateEmptyGroup(SMESH.NODE, "aGroup")
23
24 # set/get group name
25 aGroup.SetName( "new name" )
26 print("name", aGroup.GetName())
27
28 # get group type (type of entities in the group, SMESH.NODE in our case)
29 print("type", aGroup.GetType())
30
31 # get number of entities (nodes in our case) in the group
32 print("size", aGroup.Size())
33
34 # check of emptiness
35 print("is empty", aGroup.IsEmpty())
36
37 # check of presence of an entity in the group
38 aGroup.Add([1,2]) # Add() method is specific to the standalone group
39 print("contains node 2", aGroup.Contains(2))
40
41 # get an entity by index
42 print("1st node", aGroup.GetID(1))
43
44 # get all entities
45 print("all", aGroup.GetIDs())
46
47 # get number of nodes (actual for groups of elements)
48 print("nb nodes", aGroup.GetNumberOfNodes())
49
50 # get underlying nodes (actual for groups of elements)
51 print("nodes", aGroup.GetNodeIDs())
52
53 # set/get color
54 import SALOMEDS
55 aGroup.SetColor( SALOMEDS.Color(1.,1.,0.));
56 print("color", aGroup.GetColor())
57
58 # ----------------------------------------------------------------------------
59 # methods specific to the standalone group and not present in GroupOnGeometry
60 # and GroupOnFilter
61 # ----------------------------------------------------------------------------
62
63 # clear the group's contents
64 aGroup.Clear()
65
66 # add contents of other object (group, sub-mesh, filter)
67 aGroup.AddFrom( aGroup2 )
68
69 # removes entities
70 aGroup.Remove( [2,3,4] )