Ansys mechanical scripting. How to get Element type ID's using mechanical scripting?

atb5dc Member Posts: 4
First Comment
edited July 2023 in Structures

This figure is taken from the worksheet tab. I'm trying to use mechanical scripting to get the element type ids for element names I'm interested in. For example, if im interested in SOLID 187, I'd like to get the element type ID's for all solid187 using mechanical scripting.

Best Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 67
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes
    Answer ✓

    @atb5dc This could be slow as we are looping over all the elements, but it should give you what you want.

    analysis = ExtAPI.DataModel.AnalysisList[0]
    resultReader = analysis.GetResultsData()
    meshData = resultReader.CreateMeshData()
    ename_to_etype_dict = {}
    etype_num_list = []
    for element_id in meshData.ElementIds:
        bool_flag, e_type_num = resultReader.GetElemType(element_id)
        if not e_type_num in etype_num_list:
            _, _, _, _, ename = resultReader.GetElemTypeProps(e_type_num)
            if ename in ename_to_etype_dict.keys():
                ename_to_etype_dict[ename] = [e_type_num]


  • atb5dc
    atb5dc Member Posts: 4
    First Comment

    awesome. thank you so much

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 115
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member

    Is it possible to extract Element Type ID of a body during the solution via Python Code object?

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

    Yes. In the python code there is a solver_data object that has a method to get a type for a given body. This object is described in the default header.