How do I get the element types/material types of all the elements a node is shared by using DPF?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 389
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
edited June 2023 in Structures

How do I get the element types/material types of all the elements a node is shared by using DPF?

Tagged:

Best Answer

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 389
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓

    You can use the following code in Mechanical Scripting console, please change the node_id and GetDataSources index accordingly.

    NOTE - Works only from 2022R1 onwards

    import mech_dpf
    import Ans.DataProcessing as dpf
    
    mech_dpf.setExtAPI(ExtAPI)
    model = dpf.Model(mech_dpf.GetDataSources(1))
    
    node_id = 1300
    
    mesh = model.Mesh
    field_nodal = mesh.NodalConnectivityPropertyField
    element_indices = field_nodal.GetEntityDataById(node_id)
    
    element_scope = mesh.ElementScoping
    all_elements = [element_scope.IdByIndex(index) for index in element_indices]
    
    e_prop = mesh.GetPropertyField("apdl_element_type")
    e_types = [e_prop.GetEntityDataById(index)[0] for index in all_elements]
    
    mat_prop = mesh.GetPropertyField("mat")
    mat_ids = [mat_prop.GetEntityDataById(index)[0] for index in all_elements]
    
    print e_types
    print mat_ids
    
    

Answers

  • dafedin
    dafedin Member Posts: 21
    First Comment Name Dropper

    Hello Ayush,

    "apdl_element_type" and "mat" are two property names. How do I find all available property names?

    Thanks