Last active
December 31, 2016 19:01
Star
You must be signed in to star a gist
getvertices definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Copyright (c) mostafa el ayoubi , 2016 | |
#Data-Shapes www.data-shapes.net , elayoubi.mostafa@gmail.com | |
#This code was inspired by Jeremy Tammik @Jeremytammik | |
def flatten(container): | |
for i in container: | |
if isinstance(i, (list,tuple)): | |
for j in flatten(i): | |
yield j | |
else: | |
yield i | |
def tostring(x): | |
return x.ToString() | |
def getgeomlist(x): | |
return list(x.get_Geometry(Options())) | |
def getvertices(x): | |
#getting geometryelements as list | |
geomelems = getgeomlist(x) | |
#getting nested instance geometry for all geometry instances | |
while any('GeometryInstance' in g for g in map(tostring,geomelems)): | |
for index,i in enumerate(geomelems): | |
if 'GeometryInstance' in i.ToString(): | |
geomelems[index] = i.GetInstanceGeometry() | |
else: | |
continue | |
geomelems = list(flatten(geomelems))[0] | |
#getting all faces, keeping meshes | |
faces = [] | |
for i in geomelems: | |
if 'Solid' in i.ToString(): | |
faces.append(list(i.Faces)) | |
elif 'Mesh' in i.ToString(): | |
faces.append(i) | |
else: | |
continue | |
faces = list(flatten(faces)) | |
#getting all meshes | |
meshes = [] | |
for f in faces: | |
if 'Mesh' in f.ToString(): | |
meshes.append(f) | |
else: | |
meshes.append(f.Triangulate()) | |
#getting all vertices | |
vertexlist = [] | |
for m in meshes: | |
vertexlist.append(list(m.Vertices)) | |
vertexlist = list(flatten(vertexlist)) | |
#creating sorted vertex string representation of object for comparison with other indice of element | |
vertexstr = ', '.join(sorted(set(map(tostring,vertexlist)))) | |
return vertexstr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment