Skip to content

Instantly share code, notes, and snippets.

@chuongmep

chuongmep/geometryfix.py

Last active Jun 20, 2020
Embed
What would you like to do?
# Created By Karam Baki, karam@aecedx.vom
# Inspired By @5devene, dimitar.ven@gmail.com
# Clone Chuongmep.com
import clr
import System
from System.Collections.Generic import *
from itertools import repeat
pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
import sys
sys.path.append('%s\IronPython 2.7\Lib' %pf_path)
import traceback
import random
import string
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from Autodesk.DesignScript.Geometry import Point as DynPoint
from Autodesk.DesignScript.Geometry import Line as DynLine
from Autodesk.DesignScript.Geometry import Curve as DynCurve
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import StructuralType
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
def tolist(obj1):
if hasattr(obj1,'__iter__'): return obj1
else: return [obj1]
def flatten(x):
result = []
try:
for el in x:
if hasattr(el, "__iter__") and not isinstance(el, basestring):
result.extend(flatten(el))
else:
result.append(el)
except:
result = x
return result
geom = UnwrapElement(IN[0])
if geom != None:
geom = tolist(geom)
else:
pass
temp_path = System.IO.Path.GetTempPath()
satOpt = SATExportOptions()
opt1 = Options()
opt1.ComputeReferences = True
#Find a 3D view type
collector1 = FilteredElementCollector(doc)
viewFamilyTypes = collector1.OfClass((ViewFamilyType))
for e in viewFamilyTypes:
if str(e.ViewFamily) == "ThreeDimensional":
viewType = e.Id
break
def NewForm_background(s1):
try:
randomname = ''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(5)])
TransactionManager.Instance.EnsureInTransaction(doc)
sat_path = '%s%s.sat' % (temp_path, randomname)
status = True
finalres = []
resultgeom = []
threedeeview = View3D.CreateIsometric(doc, viewType)
threedeeviewid = threedeeview.Id
kilist = List[ElementId]([threedeeviewid])
tid = []
for each in s1:
tid.append(each.Id)
ielements = List[ElementId](tid)
threedeeview.IsolateElementsTemporary(ielements)
collectorinside = FilteredElementCollector(doc,threedeeviewid).ToElements()
elemento = []
for k in collectorinside:
elemento.append(int(str(k.Id)))
for each in s1:
if int(str(each.Id)) in elemento:
doc.Export(temp_path, randomname, kilist, satOpt)
eachlist = Geometry.ImportFromSAT(sat_path)
tmplist = []
for e in eachlist:
tmplist.append(e)
resultgeom.append(tmplist)
System.IO.File.Delete(sat_path)
else:
resultgeom = [None]
break
doc.Delete(threedeeview.Id)
finalres.append(flatten(resultgeom))
TransactionManager.Instance.TransactionTaskDone()
return finalres
except:
return traceback.format_exc(),''
result = NewForm_background(geom)
OUT = flatten(result)
satOpt.Dispose()
opt1.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.