Get Exterior Faces Of Walls From Linked File

Hi, guys I ran into the issue with HostObjectUtils.GetSideFaces, it’s works well if element is not linked as you can see in picture below

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument


surfaces = []
walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType().ToElements()
for wall in walls:
    side_face = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior)[0]
    surface = wall.GetGeometryObjectFromReference(side_face).ToProtoType()[0]
    surfaces.append(surface)


OUT = surfaces

But when I tried to feed linked wall elements the error is raising. Do you have any suggestions or where I can learn how to avoid that error? Thank you all in advance

That’s snippet of code below to obtain walls from link

import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
import System
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)


doc = DocumentManager.Instance.CurrentDBDocument
links = FilteredElementCollector(doc).OfClass(RevitLinkInstance)


link_docs = [link.GetLinkDocument() for link in links]

category = IN[0]
error_reports = []
result = []

for link_doc in link_docs:
    try:
    	errorReport = None
    	result += FilteredElementCollector(link_doc).OfClass(Wall)
    except:
    	import traceback
    	error_report = traceback.format_exc()
    	error_reports.append(error_report)

if len(error_reports) == 0:
	OUT = result
else:
	OUT = error_reports

And after code pretty much the same with the exception of input for walls

walls = IN[0]
surfaces = []
for wall in walls:
    side_face = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior)[0]
    surface = wall.GetGeometryObjectFromReference(side_face).ToProtoType()[0]
    surfaces.append(surface)

OUT = surfaces

Not at the PC to check, but I recall that as the walls aren’t in the document they aren’t actually wall objects in the API, but instead LinkElement objects. If you merge the two Python blocks into one I believe you should be able to progress as intended though as you’re collecting wall elements in the ‘get walls from link’ Python.

another way maybe could be genius loci compound surface reference…it give you the surfaces exterior/interiør as well and should work on link

1 Like

Hi,

you need to Unwrap the input elements to expose them to the Revit API

walls = UnwrapElement(IN[0])

1 Like

Thank you so much, it worked :sunglasses: