How to get Geometry Data from Mechanical Model via Script

Options
Mike.Thompson
Mike.Thompson Member, Employee Posts: 316
First Answer First Anniversary First Comment 5 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
    First Answer First Comment First Anniversary Ansys Employee
    admin
    Options

    Thanks, Mike!

  • kanchan_cadfem
    kanchan_cadfem Member Posts: 18
    First Anniversary First Comment 5 Likes First Answer
    Options

    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)