Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select Room Edges

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
mrensing
1336 Views, 8 Replies

Select Room Edges

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?

8 REPLIES 8
Message 2 of 9
naveen.kumar.t
in reply to: mrensing

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.

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 9

Hi,

 

please note that a Room could be defined by

 

  • the center line of a wall (depending on calculation settings)
  • an Element in a linked document
  • a Room separation line

 

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

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 9
mrensing
in reply to: 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

Message 5 of 9
Revitalizer
in reply to: mrensing

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

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 9
mrensing
in reply to: 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.

Message 7 of 9
Revitalizer
in reply to: mrensing

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 8 of 9
mastjaso
in reply to: mrensing

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.

Message 9 of 9
Revitalizer
in reply to: mastjaso

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

 




Rudolf Honke
Software Developer
Mensch und Maschine





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community