Room Boundary Location

We already had a look at

enabling the room volume computation

in C#.
Here is a closely related question that also prompted me to implement something similar in VB for a change.

Question:
Could you please provide some VB.NET code showing how to set the Autodesk.Revit.Rooms.BoundaryLocationType in the document, for instance to ‘WallCenter’?

Answer:
The boundary location type is applied when calculating the room volume.
These settings are defined by the document settings volume calculation options.
The post mentioned above discusses how to access and modify these settings.

I implemented a VB.NET sample application RoomBoundaryLocation for you to demonstrate this in VB as well.
Here is the mainline code of its Execute method:


Public Function Execute( _
  ByVal commandData As ExternalCommandData, _
  ByRef message As String, _
  ByVal elements As ElementSet) _
  As CmdResult _
  Implements IExternalCommand.Execute
  Dim app As Application = commandData.Application
  Dim doc As Document = app.ActiveDocument
  Dim opt As VolumeCalculationOptions _
    = doc.Settings.VolumeCalculationSetting _
      .VolumeCalculationOptions
  opt.VolumeComputationEnable = True
  opt.RoomAreaBoundaryLocation _
    = Rooms.BoundaryLocationType.WallCenter
  doc.Settings.VolumeCalculationSetting _
    .VolumeCalculationOptions = opt
  Dim volumes As List(Of String) = New List(Of String)
  Dim els As ElementSet = doc.Selection.Elements
  Dim e As Autodesk.Revit.Element
  For Each e In els
    If TypeOf e Is Room Then
      Dim room As Room = CType(e, Room)
      volumes.Add(room.Volume.ToString("0.##"))
      'Else
      '  volumes.Add("Not a room")
    End If
  Next
  If 0 = volumes.Count Then
    message = "Please select some rooms."
  Else
    Dim s As String = _
      +"Selected room volumes in cubic feet: " _
      + String.Join(", ", volumes.ToArray()) _
      + "."
    MsgBox(s)
  End If
  Return CmdResult.Failed
End Function

Here are some sample rooms and spaces selected in the Revit user interface:

Selected rooms and spaces

This is the resulting dialogue displayed by running the command:

Selected room volumes

Here is the complete Visual Studio solution
RoomBoundaryLocation
implementing the new command.


Comments

2 responses to “Room Boundary Location”

  1. do we an example above in C# as well?

  2. Dear Ricky,
    Come on, you’re a big boy, you can do that for yourself now, can’t you?
    http://thebuildingcoder.typepad.com/blog/2009/07/porting-from-c-to-vbnet.html
    http://thebuildingcoder.typepad.com/blog/2010/02/kean-on-reflector.html
    http://thebuildingcoder.typepad.com/blog/2013/03/parameter-displayunittype-and-decompilers.html#4
    If you can’t, for some reason, then much more recent C# code determining the room boundary is included in the Revit add-in part of my cloud-based round-trip 2D Revit model editing project:
    http://thebuildingcoder.typepad.com/blog/2013/03/revit-2014-api-and-room-plan-view-boundary-polygon-loops.html±#3
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading