How to get Geometry Data from Mechanical Model via Script

Mike.Thompson
Mike.Thompson Member, Employee Posts: 239
First Anniversary First Comment 5 Likes Ansys Employee
edited June 2023 in Structures

You can find many relevant geometry entities with the script below. Each has their own properties like Face.Area or Body.Volume

Verts=[]
for Assembly in ExtAPI.DataModel.GeoData.Assemblies:
    for Part in Assembly.Parts:
        for Body in Part.Bodies:
            for Face in Body.Faces:
                for Edge in Face.Edges:
                    for Vertex in Edge.Vertices:
                        Verts.append(Vertex)
print len(Verts)
Tagged:

Comments

  • Chris Harrold
    Chris Harrold Member, Administrator, Employee Posts: 100
    First Anniversary First Answer Ansys Employee Solution Developer Community of Practice Member
    admin

    Thanks, Mike!

  • kanchan_cadfem
    kanchan_cadfem Member Posts: 15
    First Anniversary First Comment 5 Likes First Answer

    small correction use AllParts instead of Parts

    in case of some geometries there are sub assemblies, that means Assembly can have more Assemblies, and in that case the above code would fail because the Assembly.Parts would return an empty list

    but with AllParts it should return all available Parts in geometry

    Verts=[]
    for Assembly in ExtAPI.DataModel.GeoData.Assemblies:
        for Part in Assembly.AllParts:
            for Body in Part.Bodies:
                for Face in Body.Faces:
                    for Edge in Face.Edges:
                        for Vertex in Edge.Vertices:
                            Verts.append(Vertex)
    print len(Verts)