Hi
Just an observation that had me scratching my head for a couple of hours that I thought I would share.
I noticed that while retrieving a room boundary, under some circumstances a boundary segment has no element. I found Jeremy's post that offered a good solution: Determining Room Boundary Segment Generating Element
It uses the ReferenceIntersector class to determine the wall Id for segments that appear to return no Element (end wall conditions). Read the post for more details. In my case the intersector always returned null even though I knew the ray was being cast in the right direction and into the offending wall. After a few hours I noticed that the user had enabled the section box in the default 3d view and changed the boundaries of the section box that excluded the room I was trying to extract the boundary from. This was resulting in the Intersector returning null. I changed my method that returns a suitable 3D view to ensure the section box is now switched off before using it in any ReferenceIntersector calls. Code below.
/// <summary> /// Retrieve a suitable 3D view from document. /// </summary> public static View3D Get3dView(Document doc, bool createIfNull) { FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(View3D)); foreach (View3D v in collector) { if (!v.IsTemplate && v.IsPerspective == false) { if (v.IsSectionBoxActive == true) {
// switch off as will cause ReferenceIntersector to fail if target elements
// outside sectionbox boundary v.IsSectionBoxActive = false; doc.Regenerate(); } return v; } } if (createIfNull == true) { return Common.clsCommonRevit.create3dView(doc); } else return null; } /// <summary> /// Creates a new 3D view /// </summary> public static View3D create3dView(Document doc) { ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast<ViewFamilyType>() .FirstOrDefault<ViewFamilyType>(x => ViewFamily.ThreeDimensional == x.ViewFamily); return View3D.CreateIsometric(doc, vft.Id); }