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

ZZ.tang
ZZ.tang Member Posts: 10
Name Dropper First Comment

ANSYS 2023R1

Tagged:

Best Answer

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 178
    First Answer First Comment 5 Likes First Anniversary
    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: 239
    First Anniversary First Comment 5 Likes Ansys Employee

    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: 10
    Name Dropper First Comment

    @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: 715
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

    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 Posts: 178
    First Answer First Comment 5 Likes First Anniversary

    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