Hi Jeremy,
Thank you for the reply. I have documented this bug below and provide associated files at the following dropbox link: https://www.dropbox.com/sh/i3b5ly5lvfucira/AABibDS6ceVf1B5YozMRuNOAa?dl=0.
I find dynamo / python easier for quickly testing out code so I've demonstrated it with that (in the Home.dyn file) though I can confirm that the exact same behaviour is produced from running a C# add-in (I also hardcoded in the UniqueIds of both the room and the revit link for ease):
This test project consists of 3 models, each one linked to the other two:
- Envelope
- FirstFloor
- 2ndFloor
When you open the first floor model, get the room from the active doc and get the boundary segments you get all 4 segments:
![2017-09-28 16_43_56-Autodesk Revit 2017 - [3D View_ {3D} - FirstFloor.rvt].png 2017-09-28 16_43_56-Autodesk Revit 2017 - [3D View_ {3D} - FirstFloor.rvt].png](https://forums.autodesk.com/t5/image/serverpage/image-id/406713iD96460ACF161FF31/image-size/large?v=v2&px=999)
But if you open the 2ndFloor model, and get the room from the linked document the method only returns 3 segments:
![2017-09-28 16_49_05-Autodesk Revit 2017 - [3D View_ {3D} - 2ndFloor.rvt].png 2017-09-28 16_49_05-Autodesk Revit 2017 - [3D View_ {3D} - 2ndFloor.rvt].png](https://forums.autodesk.com/t5/image/serverpage/image-id/406719i99F294651B770BEA/image-size/large?v=v2&px=999)
I think this is because if you have two linked models in your main model, and you get an object from one of them, from that object/document's perspective the other link is closed (since it's open in the main model).
I ran into this with hosted objects as well. We had two architecture models and an electrical one. If an electrical outlet in the elec model is hosted to the other architectural model, when I try and get the outlet's host it gives me the link element id which will give me the linkinstance but the link document returns null. The workaround with hosting is to get all linkinstances in the mainmodel and find the name that matches and then use the unique id to get the host element from there, though this is rather inelegant and doesn't help with a built-in function like GetBoundarySegments().
Regardless, since GetBoundarySegments() returns a BoundarySegment object with a LinkedElementId, it would still be helpful to get the boundary segment even if the link document isn't loaded from the room's perspective. If I had the 4th boundary segment and the linked element id I could still use a similar approach of checking the loaded documents from the main model for it, but without it I'm completely unable to know if my add-in missed a wall without computing the room's geometry.
The Dynamo python code I used is:
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
import math
import time
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
clr.AddReference("System")
from System.Collections.Generic import List
from System.Collections.Generic import Dictionary
outList = []
room = doc.GetElement("3c662375-fe38-44bf-a8c0-129e77cf6e67-00000a3f")
if room is None:
lnk = doc.GetElement("0a513a3a-fc7d-4ce7-9e68-e541127e38d9-00000924")
lnkDoc = lnk.GetLinkDocument()
room = lnkDoc.GetElement("3c662375-fe38-44bf-a8c0-129e77cf6e67-00000a3f")
spatOpts = SpatialElementBoundaryOptions()
spatOpts.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish
spatOpts.StoreFreeBoundaryFaces = True
boundSeg = room.GetBoundarySegments(spatOpts)
count = 0;
for i in boundSeg:
for j in i:
count = count + 1
#Assign your output to the OUT variable.
OUT = room, count