How to retrieve the face with the largest area
Akane Ito
Member Posts: 26
**
in Structures
I want to retrieve the ID of the face with the largest area among those selected in 'named selection'
0
Best Answers
-
my_NS = ExtAPI.DataModel.GetObjectsByName('Casing')[0] geodata = ExtAPI.DataModel.GeoData area = 0 my_id = 0 for face_id in my_NS.Ids: if geodata.GeoEntityById(face_id).Area >area: area = geodata.GeoEntityById(face_id).Area my_id = face_id print('Face Id is: ' + str(my_id) + ' and area is: ' + str(area))
0 -
You can also use a python sort method on a list and sort on the Area property. Then look at the last in the list. This is less coding and probably faster than a for loop.
0 -
One way to go could be:
my_NS = ExtAPI.DataModel.GetObjectsByName('Casing')[0] geodata = ExtAPI.DataModel.GeoData face_tuples = [(geodata.GeoEntityById(face_id), geodata.GeoEntityById(face_id).Area) for face_id in my_NS.Ids] sorted_faces = sorted(face_tuples, key=lambda face: face[1]) print('Face Id is: ' + str(sorted_faces[-1][0].Id) + ' and area is: ' + str(sorted_faces[-1][1]))
0
Answers
-
@Mike.Thompson
Please teach me the specific method you just told me.
I don't want just the largest area, but I want to get up to the second largest one.0 -
Thank you, I was able to do it with the method you taught me
1