Hello,
how do i use Geometry correctly in PyRevit, how can i replicate what i did in dynamo, look
i want the real perimeter of slanted roofs … who is able to change my script, that it also runs on Python, clean.
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Access the Revit application and document
app = DocumentManager.Instance.CurrentUIApplication
doc = DocumentManager.Instance.CurrentDBDocument
roofs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Roofs).WhereElementIsNotElementType().ToElements()
results = [] # list for the output results
# 🎯 get ... what ever
for elem in roofs:
if not elem.__class__ == [].__class__ : elem = [elem] #ensure that elem is a list, not an individual object, so that we can always prepare for a loop
for e in elem: #for every element
edges = [] #an empty list for the edges to process
processed = [] #the list of processed edges which we want to keep
geos = e.get_Geometry(Options()) #the geometry
for geo in geos: #for every geometry found
if geo.__class__ == Autodesk.Revit.DB.Solid: #if the geomtry is a solid
faces = geo.Faces #get the faces
for face in faces: #for every face
if face.FaceNormal.Z > 0.00001: [edges.append(i) for loop in face.EdgeLoops for i in loop] #if it is pointing up, add all of it's edges to the edges list
pnts = [e.AsCurve().Evaluate(0.5,True) for e in edges] #get all the mid points of the edges
for i in range(len(edges)): #for every item in the list of edges
e = edges.pop(0) #remove the edge to process
p = e.AsCurve().Evaluate(0.5,True) #get the midpoint
distSum = sum([1 for i in pnts if i.DistanceTo(p) == 0]) #get the count of midpoints which are equal to the midpoint being evaluated
if distSum == 1: processed.append(e.AsCurve().ToProtoType()) #if the count was 0 the edge isn't shared and is on the perimeter
results.append(processed) #append the processed edges to our results list
OUT = results #return the results list to the Dynamo environment
KR
Andreas