How to select geometry from GUI though script (Highlight in GUI,Not using Named Selection)

ZZ.tang
ZZ.tang Member Posts: 23
10 Comments First Anniversary Name Dropper
**

ANSYS 2023R1

Tagged:

Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 331
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓
    my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    my_selection.Ids = [27,28]
    ExtAPI.SelectionManager.ClearSelection()
    ExtAPI.SelectionManager.AddSelection(my_selection)
    

    Alternatively:

    ...
    ExtAPI.SelectionManager.NewSelection(my_selection)
    

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 368
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    Note there is also the option to not actually "select" the geometry in the selection manager, but to simply highlights it in the graphics window. This is useful when having multiple types of selections (i.e. primary and secondary) and you may want them to display in different colors before performing an operation on them....
    You can use this general graphics method to create non-clickable graphics of the geometry. There are properties of the created "MyFaceGraphic" like color, DepthTest (is it hidden when something is in front of it), toggle showing points on face or not, etc....

    MyFaceGraphic = ExtAPI.Graphics.Scene.Factory3D.CreateGeometry(MyFace)

    ExtAPI.Graphics.Scene.Clear() to remove all custom graphics from the GUI window.

    Also a good idea to use this for faster graphics processing:
    with ExtAPI.Graphics.Suspend():
    #do something

  • ZZ.tang
    ZZ.tang Member Posts: 23
    10 Comments First Anniversary Name Dropper
    **

    @Landon Mitchell Kanner said:

    my_selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    my_selection.Ids = [27,28]
    ExtAPI.SelectionManager.ClearSelection()
    ExtAPI.SelectionManager.AddSelection(my_selection)
    

    Alternatively:

    ...
    ExtAPI.SelectionManager.NewSelection(my_selection)
    

    I have an additional question, is there any way to select a geometry in specified location without using the named selection?

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

    Not straightforward, but you could use GeoData to access geometrical properties of your model (for example, areas of surfaces), and select the entities that match your criteria. Using named selections would probably be more efficient, though.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 331
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    is there any way to select a geometry in specified location without using the named selection?

    Yes. See for example:
    https://discuss.ansys.com/discussion/2839/how-to-get-a-body-or-node-id-associated-with-a-known-coordinate-point