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