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

atb5dc
atb5dc Member Posts: 4
First Comment
edited July 14 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: 42
    10 Comments 5 Answers First Anniversary Solution Developer Community of Practice Member
    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: 80
    25 Answers 25 Likes 10 Comments First Anniversary

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

    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.