I've selected a face manually in Mechanical and would like to know to which body in the Mechanical tree it corresponds to.
If a face is selected manually then its geoid can be retrieved through the selection manager with:
face_sel = ExtAPI.SelectionManager.CurrentSelection
face_sel contains a list of Ids of the selected geo-entities. If only one face is selected we can assume that face_sel is a list of only one element. In this case, the geobody corresponding to this selected face can be obtained through:
my_geobody = geoData.GeoEntityById(face_sel.Ids).Bodies
And finally the object in the tree can be obtained with:
my_tree_body = ExtAPI.DataModel.Project.Model.Geometry.GetBody(my_geobody)