void DetermineAdjacentElementLengthsAndWallAreas(
Room room)
{
Document doc = room.Document;
// 'Autodesk.Revit.DB.Architecture.Room.Boundary' is obsolete:
// use GetBoundarySegments(SpatialElementBoundaryOptions) instead.
//BoundarySegmentArrayArray boundaries = room.Boundary; // 2011
IList<IList<BoundarySegment>> boundaries
= room.GetBoundarySegments(
new SpatialElementBoundaryOptions() ); // 2012
// a room may have a null boundary property:
int n = 0;
if( null != boundaries )
{
//n = boundaries.Size; // 2011
n = boundaries.Count; // 2012
}
Debug.Print(
"{0} has {1} boundar{2}{3}",
Util.ElementDescription( room ),
n, Util.PluralSuffixY( n ),
Util.DotOrColon( n ) );
if( 0 < n )
{
int iBoundary = 0, iSegment;
//foreach( BoundarySegmentArray b in boundaries ) // 2011
foreach( IList<BoundarySegment> b in boundaries ) // 2012
{
++iBoundary;
iSegment = 0;
foreach( BoundarySegment s in b )
{
++iSegment;
//Element neighbour = s.Element; // 2015
Element neighbour = doc.GetElement( s.ElementId ); // 2016
//Curve curve = s.Curve; // 2015
Curve curve = s.GetCurve(); // 2016
double length = curve.Length;
Debug.Print(
" Neighbour {0}:{1} {2} has {3}"
+ " feet adjacent to room.",
iBoundary, iSegment,
Util.ElementDescription( neighbour ),
Util.RealString( length ) );
if( neighbour is Wall )
{
Wall wall = neighbour as Wall;
Parameter p = wall.get_Parameter(
BuiltInParameter.HOST_AREA_COMPUTED );
double area = p.AsDouble();
LocationCurve lc
= wall.Location as LocationCurve;
double wallLength = lc.Curve.Length;
//Level bottomLevel = wall.Level; // 2013
Level bottomLevel = doc.GetElement( wall.LevelId ) as Level; // 2014
double bottomElevation = bottomLevel.Elevation;
double topElevation = bottomElevation;
p = wall.get_Parameter(
BuiltInParameter.WALL_HEIGHT_TYPE );
if( null != p )
{
ElementId id = p.AsElementId();
Level topLevel = doc.GetElement( id ) as Level;
topElevation = topLevel.Elevation;
}
double height = topElevation - bottomElevation;
Debug.Print(
" This wall has a total length,"
+ " height and area of {0} feet,"
+ " {1} feet and {2} square feet.",
Util.RealString( wallLength ),
Util.RealString( height ),
Util.RealString( area ) );
}
}
}
}
}