i have continued work on my script and i am almost achieving the desired output.
But at the final strech somethign wierd seems to happen.
I managed to get the interior and exterior faces of walls and intersect these with the other faces but the output i get are walls wich are perpendicular to the checking wall:
for example the red walls clash with the green (atleast by the output of my code)
while i would only expect the blue and yellow one to trigger an intersect.
below my code and pyrevit results:
code:
# imports
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
from pyrevit import revit
# doc & appplication
doc = revit.doc
uidoc = revit.uidoc
# collect walls in model
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
faces = []
valid_walls = {}
# Iterate through all walls to find intersections
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
for wall in walls:
wall_faces = []
# get interiorface
extSide = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Exterior)
for e in extSide:
extface = wall.GetGeometryObjectFromReference(e)
if extface == None:
continue
else:
wall_faces.append(extface)
print(extface)
# get exteriorface
intSide = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Interior)
for i in intSide:
intface = wall.GetGeometryObjectFromReference(i)
if intface == None:
continue
else:
print(intface)
wall_faces.append(intface)
print('---------------------')
# Add wall_faces to general faces list
if len(wall_faces) > 0:
valid_walls[wall] = wall_faces
for wall in valid_walls:
print("Wall {}: {}".format(wall.Id, valid_walls[wall]))
print('INTERSECTING')
print('-------------------------------------')
intersecting_walls_dict = {}
for wall1, faces1 in valid_walls.items():
for wall2, faces2 in valid_walls.items():
if wall1.Id != wall2.Id:
for face1 in faces1:
for face2 in faces2:
intersection_result = face1.Intersect(face2)
if intersection_result == FaceIntersectionFaceResult.Intersecting:
if wall1 not in intersecting_walls_dict:
intersecting_walls_dict[wall1] = []
if wall2 not in intersecting_walls_dict[wall1]:
intersecting_walls_dict[wall1].append(wall2)
for wall, intersecting_walls in intersecting_walls_dict.items():
print("Wall ID: {} intersects with:".format(wall.Id))
for intersecting_wall in intersecting_walls:
print(" - Wall ID: {}".format(intersecting_wall.Id))
print()
i based my script on this node(Wall edges references) from @Alban_de_Chasteigner (genius_loci):
#Alban de Chasteigner 2019
#twitter : @geniusloci_bim
#geniusloci.bim@gmail.com
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
def isAlmostEqualTo(v1, v2):
return v1.IsAlmostEqualTo(v2)
def isParallel(v1,v2):
return v1.CrossProduct(v2).IsAlmostEqualTo(XYZ(0,0,0))
items = UnwrapElement(IN[0])
if not hasattr(items, '__iter__'):
items = [items]
extFaces,intFaces,allExtEdges,allIntEdges,allExtReferences,allIntReferences,allextHEdges,allextHReferences,allintHEdges,allintHReferences=[],[],[],[],[],[],[],[],[],[]
opt = Options()
opt.ComputeReferences = True
opt.IncludeNonVisibleObjects = True
for item in items:
extSide = HostObjectUtils.GetSideFaces(item,ShellLayerType.Exterior)
for e in extSide:
extFace = item.GetGeometryObjectFromReference(e)
extFaces.append(extFace)
intSide = HostObjectUtils.GetSideFaces(item,ShellLayerType.Interior)
for i in intSide:
intFace = item.GetGeometryObjectFromReference(i)
intFaces.append(intFace)
for obj in item.get_Geometry(opt):
extEdges,intEdges,extReferences,intReferences,extHEdges,extHReferences,intHEdges,intHReferences=[],[],[],[],[],[],[],[]
if isinstance(obj, Solid):
for edges in obj.Edges:
if round(edges.AsCurve().GetEndPoint(0).ToPoint().Z,10) != round(edges.AsCurve().GetEndPoint(1).ToPoint().Z,10):
if edges.GetFace(0) in extFaces :
extEdges.append(edges.AsCurve().ToProtoType())
extReferences.append(edges.Reference)
if edges.GetFace(0) in intFaces :
intEdges.append(edges.AsCurve().ToProtoType())
intReferences.append(edges.Reference)
else :
line = item.Location.Curve
lineDir = line.GetEndPoint(1) - line.GetEndPoint(0)
if not isinstance(edges.AsCurve(), Arc):
faceNormal = edges.AsCurve().Direction.Normalize()
if isParallel(faceNormal,lineDir):
if edges.GetFace(0) in extFaces :
extHEdges.append(edges.AsCurve().ToProtoType())
extHReferences.append(edges.Reference)
if edges.GetFace(0) in intFaces :
intHEdges.append(edges.AsCurve().ToProtoType())
intHReferences.append(edges.Reference)
allExtEdges.append(extEdges)
allIntEdges.append(intEdges)
allExtReferences.append(extReferences)
allIntReferences.append(intReferences)
allextHEdges.append(extHEdges)
allextHReferences.append(extHReferences)
allintHEdges.append(intHEdges)
allintHReferences.append(intHReferences)
if isinstance(IN[0], (list)): OUT = filter(None, allExtEdges),filter(None,allExtReferences),filter(None,allIntEdges),filter(None,allIntReferences),filter(None,allextHEdges),filter(None,allextHReferences),filter(None,allintHEdges),filter(None,allintHReferences)
else: OUT = filter(None, allExtEdges)[0],filter(None,allExtReferences)[0],filter(None,allIntEdges)[0],filter(None,allIntReferences)[0],filter(None,allextHEdges)[0],filter(None,allextHReferences)[0],filter(None,allintHEdges)[0],filter(None,allintHReferences)[0]
Wich give the following dynamo, but i shortend it to just retrieve te faces and let those intersect to find the adjecent walls: