How to get a list of each object in named selection use script
Ansys 2023r1
And how to get the location or area information of these geometrys.
Best Answers
-
def Geo_list():
geo_list=[]
for geoid in ExtAPI.SelectionManager.CurrentSelection.Ids :
geoEntity = DataModel.GeoData.GeoEntityById(geoid)
geo_list.append(geoEntity)
return geo_listfor geo in Geo_list():
Print(geo.Area)0 -
all_named_selections = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.NamedSelection) for ns in all_named_selections: print "named selection: {}".format(ns.Name) entities = ns.Entities for entity in entities: print " entity: {}".format(entity.Id) print " area: {}".format(entity.Area) print " centroid: {}".format(entity.Centroid)
Note: Depending on the type of the entity that is in the named selection (body, face, edge, vertex, node, element, or element face), the last two lines of the above code may behave differently. This version was tested using a face Named Selection.
0
Answers
-
Hi @ZZ.tang , the code you shared will work on the active selection in Mechanical, not on a named selection. For it to work on a named selection, the principle will be the same:
- access the named selection (for example by its name)
- check the ids of the entities scoped in that NS
- use GeoData to obtain information on the geometry
0