How to get Geometry Data from Mechanical Model via Script

Mike.Thompson
Mike.Thompson Member, Employee Posts: 367
25 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
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: 183
    100 Comments 5 Answers First Anniversary Ansys Employee
    admin

    Thanks, Mike!

  • kanchan_cadfem
    kanchan_cadfem Member Posts: 20
    10 Comments First Anniversary 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)
    


  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 282
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited October 2024

    if we want the vertices associated with the face (edges will have 2 so in a square with 4 edges we get 8 vertices with the above - one the other hand we get 4 vertices if we get them from the Faces as below):

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