Created
June 4, 2020 16:56
-
-
Save chuongmep/0e67d97dcf5fa8ee2dc85e880d91861d to your computer and use it in GitHub Desktop.
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
import clr | |
clr.AddReference('ProtoGeometry') | |
from Autodesk.DesignScript.Geometry import Surface as DSSurf | |
clr.AddReference('RevitAPI') | |
from Autodesk.Revit.DB import* | |
clr.AddReference('RevitNodes') | |
import Revit | |
clr.ImportExtensions(Revit.GeometryConversion) | |
import sys | |
pyt_path = r'C:\\Program Files (x86)\\IronPython 2.7\\Lib' | |
sys.path.append(pyt_path) | |
import collections | |
def tolist(input): | |
if isinstance(input,list): | |
return UnwrapElement(input) | |
else: | |
return [UnwrapElement(input)] | |
def flatten(l): | |
for el in l: | |
if isinstance(el, collections.Iterable) and not isinstance(el, basestring): | |
for sub in flatten(el): | |
yield sub | |
else: | |
yield el | |
def tostring(x): | |
return x.ToString() | |
def getgeomlist(x,opt): | |
return list(x.get_Geometry(opt)) | |
def getlength(c): | |
return c.Length | |
def getfaces(x,opt): | |
#getting geometryelements as list | |
geomelems = getgeomlist(x,opt) | |
#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)) | |
#getting all faces, keeping meshes | |
faces = [] | |
for i in geomelems: | |
if 'Solid' in i.ToString(): | |
faces.append(list(i.Faces)) | |
eli |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment