face.Intersect(face) results

Hi everybody,

Folowing the topic at the bottom, i found a way to retrieve the exterior and interior faces of walls using the revit api. But the when i use the face.intersect method i get some unexpected results.

The script should only find that the blue and yellow wall are intersecting (maybe it would also take the connecting red one).

But right now i get results whereby my script says that the blue and green wall both intesect with all the red onces.

And the blue and yellow don’t even get an intersection result.
U can also see that all walls have a number of intersection wich (too me) is clearly not the case.

Any feedback and input is kindly appriciated :smiley:

Below a screenshot so u understand the explanation and my code:

# imports
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *

from pyrevit import revit, script

# 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.Name))
    for intersecting_wall in intersecting_walls:
        print(" - Wall ID: {}".format(intersecting_wall.Name))
    print()

output = script.get_output()

data = []
typenr = 1
for wall, intersecting_walls in intersecting_walls_dict.items():
    dataset = []
    dataset.append(typenr)
    dataset.append(wall.Name)
    for intersecting_wall in intersecting_walls:
        dataset.append(intersecting_wall.Name)
    typenr = typenr+1
    data.append(dataset)

output.print_table(table_data = data,
                   title="Wallsystems",
                   columns=["System Nr", "Walltype 1", "Walltype 2", "Wall 3"],
                   formats=['', '', '', ''],)

output.log_success('script succesfull')

ADDITIONAL INFORMATION:
I have had some messages an tips about using joined walls for this issues. There are a few reason why i can’t use that approach here:

  • i can’t count the fact that people will join all these walls correctly (human error)
  • even if everything was joined then i would fined to many joins:
    walls joined et the ends and corners
    walls joined at the top and bottom of the walls
  • there are a few to tricks to filter these out but still it also a procees to do that
  • lastly and most importanty for me:

This script will also need to work with linked models where the structural walls are in a different model and so these can’t be joind with the walls from our model.
On top of that is could even be the case that the script is run by other company and so i can’t rely on modelprinciples from our company alone.

These are the reasons why i use the intersect face method.
It just tackle al of the above without major modelling and geometry implications.

Preivous topic:

Fore those intrested:

This method in the revit API doesn’t work “as advertised” :slight_smile:
U can find more in info on the revitapi forum:
Solved: Re: Surprising results from Face.Intersect(face) method - Autodesk Community - Revit Products

or the building coder:
The Building Coder: Face Intersect Face is Unbounded (typepad.com)

Sad tho that after al these year this didn’t get fixed.

1 Like