# Groups

### Creation of a group

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

# create two vertices

p0 = geompy.MakeVertex(0. , 0. , 0. )

p200 = geompy.MakeVertex(200., 200., 200.)

# create a box on two points

Box = geompy.MakeBoxTwoPnt(p0, p200)

# create group on box's faces

group = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])

# add objects to the group

SubFaceList = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])

for i in [0, 3, 5] :

FaceID = geompy.GetSubShapeID(Box, SubFaceList[i])

geompy.AddObject(group, FaceID)

# add to the group all the given shapes from the list

# (no errors, if some shapes are already included)

geompy.UnionList(group, [SubFaceList[0], SubFaceList[2], SubFaceList[5]])

# remove object from the group

geompy.RemoveObject(group, FaceID)

# remove from the group all the given shapes

# (no errors, if some shapes are not included)

geompy.DifferenceList(group, [SubFaceList[2], SubFaceList[3], SubFaceList[4]])

id_group1 = geompy.addToStudy(group, "Group1")

# display group's contents

gg.createAndDisplayGO(id_group1)

salome.sg.updateObjBrowser(1)

###

###

### Adding an object in a group.

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

# create two vertices

p0 = geompy.MakeVertex(0. , 0. , 0. )

p200 = geompy.MakeVertex(200., 200., 200.)

# create a box on two points

Box = geompy.MakeBoxTwoPnt(p0, p200)

# create group on box's faces

group = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])

# add objects to the group

SubFaceList = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])

for i in [0, 3, 5] :

FaceID = geompy.GetSubShapeID(Box, SubFaceList[i])

geompy.AddObject(group, FaceID)

id_group1 = geompy.addToStudy(group, "Group1")

# display group's contents

gg.createAndDisplayGO(id_group1)

salome.sg.updateObjBrowser(1)

### Removing an object from a group

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

# create two vertices

p0 = geompy.MakeVertex(0. , 0. , 0. )

p200 = geompy.MakeVertex(200., 200., 200.)

# create a box on two points

Box = geompy.MakeBoxTwoPnt(p0, p200)

# create group on box's faces

group = geompy.CreateGroup(Box, geompy.ShapeType["FACE"])

# add objects to the group

SubFaceList = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])

for i in [0, 3, 5] :

FaceID = geompy.GetSubShapeID(Box, SubFaceList[i])

geompy.AddObject(group, FaceID)

# add to the group all the given shapes from the list

# (no errors, if some shapes are already included)

geompy.UnionList(group, [SubFaceList[0], SubFaceList[2], SubFaceList[5]])

# remove object from the group

geompy.RemoveObject(group, FaceID)

id_group1 = geompy.addToStudy(group, "Group1")

# display group's contents

gg.createAndDisplayGO(id_group1)

salome.sg.updateObjBrowser(1)