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

atb5dc
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: 85
    Photogenic 5 Likes Name Dropper Ansys Employee
    ✭✭✭✭
    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:
            etype_num_list.append(e_type_num)
            _, _, _, _, ename = resultReader.GetElemTypeProps(e_type_num)
            if ename in ename_to_etype_dict.keys():
                ename_to_etype_dict[ename].append(e_type_num)
            else:
                ename_to_etype_dict[ename] = [e_type_num]
    
    print(ename_to_etype_dict)
    

Answers

  • atb5dc
    atb5dc Member Posts: 4
    First Comment
    **

    awesome. thank you so much

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 175
    100 Comments Photogenic Ansys Employee 5 Likes
    ✭✭✭✭

    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: 327
    25 Answers First Anniversary 100 Comments 25 Likes
    ✭✭✭✭

    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.