How to get Geometry Data from Mechanical Model via Script
Mike.Thompson
Member, Employee Posts: 367
✭✭✭✭
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:
1
Comments
-
Thanks, Mike!
0 -
small correction use
AllParts
instead ofParts
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 listbut with
AllParts
it should return all available Parts in geometryVerts=[] 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)
2 -
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)
0