Get the sketch lines of the roof

I’ve been reading up on this post How to get the sketch lines of the roof
But have found that Springs.Collector.ElementSketch node works fine as shown, but I was curious if a filteredelementcollector could be used to get all the roof elements but encountered an issue when editing the python code contained in the ElementSketch node (I work on a copy BTW)
image

See moded python code below…

#Copyright(c) 2016, Dimitar Venkov
# @5devene, dimitar.ven@gmail.com

import clr
import math

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

# GET ALL ROOF ELEMENTS
roofs = FilteredElementCollector(doc , doc.ActiveView.Id)\
        .OfCategory(BuiltInCategory.OST_Roofs)\
        .ToElements()

def tolist(obj1):
	if hasattr(obj1,"__iter__"): return obj1
	else: return [obj1]
	
#ORIGINAL INPUT
#elements = UnwrapElement(tolist(IN[0]))
elements = UnwrapElement(tolist(roofs))
# INPUT IN[1] REPLACED WITH TRUE
getModel = True	#IN[1]

accepted_mc = "Autodesk.Revit.DB.ModelLine,Autodesk.Revit.DB.ModelArc, Autodesk.Revit.DB.ModelEllipse, Autodesk.Revit.DB.ModelHermiteSpline, Autodesk.Revit.DB.ModelNurbSpline"

def almost_eq(line, mc):
	line2 = mc.Location.Curve
	xyz1 = line.Evaluate(0.5, True)
	if not line2.IsBound:
		xyz2 = line2.Center
		try: xyz1 = line.Center
		except: pass
	else:
		xyz2 = line2.Evaluate(0.5, True)
	if xyz1.DistanceTo(xyz2) <= 0.0001:
		return True
	else:
		return False

def clean1(l1):
	for i in xrange(len(l1) ):
		l1[i] = [x for x in l1[i] if x != None]
	return l1

def getSketch(el1):
	try:
		sk1 = doc.GetElement(ElementId(el1.Id.IntegerValue) - 1)
	except:
		sk1 = None
	if not getModel and sk1 is not None and sk1.GetType().ToString() == 'Autodesk.Revit.DB.Sketch':
		profile = sk1.Profile
	else:
		t1 = SubTransaction(doc)
		t1.Start()
		deleted = doc.Delete(el1.Id)
		t1.RollBack()
		
		profile, mc = CurveArrArray(), []
		for d in deleted:
			test_el = doc.GetElement(d)
			el_type = test_el.GetType().ToString()
			if el_type == "Autodesk.Revit.DB.Sketch":
				profile = test_el.Profile
				if not getModel:
					break
			elif getModel and el_type in accepted_mc :
				mc.append(test_el)

	ordered_mc = [ [None] * i.Size for i in profile] if getModel else []
	curves = [ [None] * i.Size for i in profile]
	for i in xrange(profile.Size):
		for j in xrange(profile[i].Size):
			curves[i][j] = profile[i][j].ToProtoType()
			if getModel:
				for k in xrange(len(mc)):
					if almost_eq(profile[i][j], mc[k]):
						ordered_mc[i][j] = mc[k].ToDSType(True)
						del mc[k]
						break
						
	return curves, clean1(ordered_mc)

TransactionManager.Instance.EnsureInTransaction(doc)
result = map(getSketch, elements)
TransactionManager.Instance.TransactionTaskDone()
OUT = elements, [r[0] for r in result], [r[1] for r in result]

Hello.

Use the GetProfiles() method:

Roof Footprint

import clr

clr.AddReference("ProtoGeometry")
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")

import DSCore
import Autodesk
import Revit

clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

from DSCore import *
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *


# Input data.
roofs = UnwrapElement(IN[0])

# List of ModelCurveArrArray.
curveLists = [roof.GetProfiles() for roof in roofs]

# Convert Model Lines to curves.
fn = lambda x: x.GeometryCurve.ToProtoType()
ProcessLists = lambda function, lists: [ProcessLists(function, item) if isinstance(item, ModelCurveArray) else function(item) for item in lists]

# Output data.
OUT = [ProcessLists(fn, curveList) for curveList in curveLists]
3 Likes

Whilst this works great I could not work out how to retrieve the parameters that are similar to those associated with the with sketch lines.
image

@EddieSaez,

You can find all you need in the properties of the FootPrintRoof class:
FootPrintRoof Class (revitapidocs.com)

Regards,