How to get a list of each object in named selection use script

ZZ.tang
ZZ.tang Member Posts: 23
10 Comments Name Dropper
**
edited December 2023 in Structures

Ansys 2023r1

And how to get the location or area information of these geometrys.

Tagged:

Best Answers

  • ZZ.tang
    ZZ.tang Member Posts: 23
    10 Comments Name Dropper
    **
    Answer ✓

    def Geo_list():
    geo_list=[]
    for geoid in ExtAPI.SelectionManager.CurrentSelection.Ids :
    geoEntity = DataModel.GeoData.GeoEntityById(geoid)
    geo_list.append(geoEntity)
    return geo_list

    for geo in Geo_list():
    Print(geo.Area)

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 319
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓
    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.

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    100 Answers 500 Comments 250 Likes First Anniversary
    ✭✭✭✭

    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