I am looking for a way to have the user select edges of a room, however I am stuck at trying to get at the edges. My initial idea was to setup a filter to select a room. Then use that room as the basis to select the edges. However, I can't get edges to highlight or even select. Any clues as to how to get to pick the edges of a room?
Solved! Go to Solution.
Solved by Revitalizer. Go to Solution.
Hi @mrensing ,
You can use the below code to select the edge directly
Reference R = uidoc.Selection.PickObject(ObjectType.Edge,"SELECT EDGE");
(OR)
If you select the room element the corresponding edges of the room element are highlighted from which you can select the edge you want.
Room r ; if(r!=null) { SpatialElementBoundaryOptions op = new SpatialElementBoundaryOptions(); op.StoreFreeBoundaryFaces = true; op.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.CoreBoundary; IList<IList<BoundarySegment>> BGs = r.GetBoundarySegments(op) as IList<IList<BoundarySegment>>; IList<ElementId> segementElementID = new List<ElementId>(); foreach(IList<BoundarySegment> BG in BGs) { foreach(BoundarySegment seg in BG) { segementElementID.Add(seg.ElementId); } } uidoc.Selection.SetElementIds(segementElementID); uidoc.ShowElements(segementElementID); uidoc.RefreshActiveView(); }
I hope this helps.
Hi,
please note that a Room could be defined by
For the first approach you mention, one picks an edge of a surrounding element.
That would not match the first case (wall center line), and I also think, the third case (Room separation line).
The second approach, highlighting the boundary elements, would make no sense if a room is defined by walls residing in a linked document, you would select the entire RevitLinkInstance.
So what could be done?
One could use BoundarySegment.GetCurve() and create ModelCurves or DetailCurves, depending on current view type.
Once created, they are selectable.
After selecting, these curve Elements could be deleted.
Revitalizer
Thanks. This helps a lot. Both replies are great and get me closer. I think I am going to have to draw detailcurves and use those as a selection input.
There is one small issue that has surfaced. The newly created detail lines are at the wall structure not, at the finish. The Area Settings for rooms are set to "At wall finish", so that should be good. Using the Revit Lookup AddIn and snooping the wall, I can view the BoundarySegments of the room. Looking at the line that makes it up, there Origin points, as well as the Length values are different that that of the Detail Line that corresponds to that segment of the room.
My code is extracting Curve from the BoundarySegment, and using that to create a new DetailCurve. I have also tried to use the curve and create a new line using the points of the curve. This also produces a Detail Lines that is at the face of structure and not the Finish face.
Attached shows an example. The left is the detail line created from the Boundary of the room which is on the right. They should be the same, but aren't
Hi,
which SpatialElementBoundaryLocation in your SpatialElementBoundaryOptions ?
You say:
'The Area Settings for rooms are set to "At wall finish"'
So did you use SpatialElementBoundaryLocation.Finish ?
Revitalizer
Thanks, I overlooked that portion. It was set to core face in the SpatialElementBoundaryOptions. I forgot that I had i had set that, and was assuming it would use the settings set in Revit's GUI.
Interestingly,
the room calculation settings are not part of the document.Settings.
In fact, it seems there is no way to get them, at all.
It would make sense to use just these current settings for getting the current room polygons.
Revitalizer
As an FYI there's a pretty severe bug with the BoundarySegments api (or at least there was as of Revit 2017, I don't know if it's been fixed but the bug is still listed as open so I assume not).
But if you are in a situation where the room is in a linked model, but your bounding element is in the active model, the Revit API will just not return those boundary segments. It won't throw an error, so it can be hard to catch, and I got pretty far into developing an add-in for use on a large hospital model and didn't discover this until we were testing on the actual model and it kind of screwed me. I ended up having to get the 'boundary segment's by looping through the room's geometry and checking which segments were low enough / parallel to the floor to get the bounding segments. I just needed their coordinates so that was good enough, to get the actual bounding elements would be even more of a pain from there.
If you know for sure your add-in will never be used in that scenario it's ok, but that model configuration isn't as uncommon as it may first appear, and I don't want you getting burned late in the game like I did.
Hi,
we also faced problems getting the room boundaries, several times in the past.
There is another method to get the polygons, e.g. using
ExporterIFCUtils.GetRoomBoundaryAsCurveLoopArray.
Also, one could export a gbXML and read the spatial geometry from the exported file (not tested so far).
But yes, it's a pain, anyway.
Revitalizer