import geompy

# find a compound imported from STEP file in the study
compound = salome.myStudy.FindObjectID("0:1:1:2").GetObject()

sb = salome.myStudy.NewBuilder() # studyBuilder needed to remove study objects

def GetObjectByName( mainObj, name, subType ):
    "In mainObj, find an object with the given name and type"
    subs = geompy.SubShapeAll( mainObj, geompy.ShapeType[subType] )
    for sub in subs:
        # publish sub in the study to learn its STEP name
        defaultName = geompy.SubShapeName( sub, mainObj )
        subStudyID = geompy.addToStudyInFather( mainObj, sub, defaultName )
        subStudyObj = salome.myStudy.FindObjectID( subStudyID )
        subName = subStudyObj.GetName()
        if subName == name:
            return subStudyObj.GetObject()
        # sub object has a different name, remove it from the study
        sb.RemoveObjectWithChildren( subStudyObj )

# get a solid by its name
solidName = "Base_Default_2"
solid = GetObjectByName( compound, solidName, "SOLID" )

# find a face in the solid by face name
faceName = "Plane_1"
face = GetObjectByName( solid, faceName, "FACE")

# update study tree
if salome.sg.hasDesktop():
  salome.sg.updateObjBrowser(1)


