How to get Geometry Data from Mechanical Model via Script

Mike.Thompson
Mike.Thompson Member, Employee Posts: 327
25 Answers First Anniversary 100 Comments 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
    5 Answers 100 Comments Photogenic Name Dropper
    admin

    Thanks, Mike!

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