Grouping Elements

Create a Group

 

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 100

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 100 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# print the result

print "Criterion: Area > 100 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# create a group consisting of faces with area > 100

aGroup = mesh.CreateGroup( SMESH.FACE, "Area > 100" )

aGroup.Add( anIds )

 

salome.sg.updateObjBrowser(1)

 

Edit a Group

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 30 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA > 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group of elements with area [20; 60] by removing elements with area > 60 from  group aGroup

aGroup.Remove(anIds)

 

# print the result

aGroupElemIDs = aGroup.GetListOfID()

print "Criterion: 20 < Area < 60 = ", len( aGroupElemIDs )

for i in range( len( aGroupElemIDs ) ):

  print aGroupElemIDs[ i ]

 

salome.sg.updateObjBrowser(1)

 

Union of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup1 = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup1.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA = 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateEqualTo()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup2 = mesh.CreateGroup( SMESH.FACE, "Area = 20" )

aGroup2.Add( anIds )

 

print "Criterion: Area = 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# create union group : area >= 20

aGroup3 = mesh.UnionGroups(aGroup1, aGroup2, "Area >= 20")

print "Criterion: Area >= 20 Nb = ", len( aGroup3.GetListOfID() )

 

# Criterion : AREA < 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 20

aGroup4 = mesh.CreateGroup( SMESH.FACE, "Area < 20" )

aGroup4.Add( anIds )

 

print "Criterion: Area < 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create union group : area >= 20 and area < 20

aGroup5 = mesh.UnionGroups(aGroup3, aGroup4, "Any Area")

print "Criterion: Any Area Nb = ", len( aGroup5.GetListOfID() )

 

salome.sg.updateObjBrowser(1)

 

Intersection of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup1 = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup1.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA < 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 60

aGroup2 = mesh.CreateGroup( SMESH.FACE, "Area < 60" )

aGroup2.Add( anIds )

 

print "Criterion: Area < 60 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create an intersection of groups : 20 < area < 60

aGroup3 = mesh.IntersectGroups(aGroup1, aGroup2, "20 < Area < 60")

print "Criterion: 20 < Area < 60 Nb = ", len( aGroup3.GetListOfID() )

 

salome.sg.updateObjBrowser(1)

 

Cut of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroupMain = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroupMain.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA < 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 60

aGroupTool = mesh.CreateGroup( SMESH.FACE, "Area < 60" )

aGroupTool.Add( anIds )

 

print "Criterion: Area < 60 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create an intersection of groups : area >= 60

aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")

print "Criterion: Area >= 60 Nb = ", len( aGroupRes.GetListOfID() )

 

salome.sg.updateObjBrowser(1)