how to get elements based on element name IDs using ansys mechanical scripting?

amusthaf Member Posts: 16
Name Dropper First Comment

for example, if I want to get all the elements of CONTAC174 of ename, how do I get it?


  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 279
    First Anniversary First Comment 5 Likes Ansys Employee

    There are lots of ways to do this but the easiest way will depend on your use case. Can you give more context? For example, is this for post processing after the solution file is available? What are you wanting to do with the Ids?

    Also, getting all contact elements is different from getting other types as contact elements do not “exist” in Mechanical. They are created at runtime while other elements for bodies exist in Mechanical directly and Ids are available assuming the model is meshed.

  • amusthaf
    amusthaf Member Posts: 16
    Name Dropper First Comment
    edited August 2023

    Hello Mike,

    Yes, Mike, I would be doing it after solving the model. I am trying to do something equivalent to the APDL commands:

    I wanted to select all the elements that corresponds to contact regions in the model and create named selection as per its geometrical selection, like if surfaces have been selected to give contact between two bodies, its corresponding elements to be grouped in "faceelements," likewise if edges being selected, it is to be grouped in "edgeelements."

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 804
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

    Hi @amusthaf , it will not be possible to create named selections of contact elements in Mechanical,as these elements are not shown in the Mechanical UI. You could use APDL command snippets to create the named selection, but the named selection will not show up in the Mechanical UI. With the Mechanical automation API, you can create named selections, but only the ones that can be created through the Mechanical UI too. There's a post about creating worksheet named selections here: You could create a named selection for the geometrical faces though (the ones meshed with SOLID187 elements in your example, on top of which the contact/target elements get created).
    Depending on what you'd like to do exactly, you can also use Solver Data API to get contact-specific data (see this page of the help: