public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
// Filtering for Room elements throws an exception:
// Input type is of an element type that exists in
// the API, but not in Revit's native object model.
// Try using Autodesk.Revit.DB.SpatialElement
// instead, and then postprocessing the results to
// find the elements of interest.
//FilteredElementCollector a
// = new FilteredElementCollector( doc )
// .OfClass( typeof( Room ) );
// Solution using SpatialElement and then
// checking for Room type
//FilteredElementCollector a
// = new FilteredElementCollector( doc )
// .OfClass( typeof( SpatialElement ) );
//foreach( SpatialElement e in a )
//{
// Room room = e as Room;
// if( null != room )
// {
// ListRoomData( room );
// }
//}
// Improvement suggested by
// Victor Chekalin using LINQ
// http://thebuildingcoder.typepad.com/blog/2011/11/accessing-room-data.html
// ?cid=6a00e553e168978833017c3690489f970b#comment-6a00e553e168978833017c3690489f970b
// --> version 2013.0.100.2
//FilteredElementCollector collector
// = new FilteredElementCollector( doc );
//var rooms = collector
// .OfClass( typeof( SpatialElement ) )
// .OfType<Room>();
//FilteredElementCollector collector
// = new FilteredElementCollector( doc );
//var rooms = collector
// .OfClass( typeof( SpatialElement ) )
// .OfType<Room>();
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( SpatialElement ) );
IEnumerable<Element> rooms = collector
.Where<Element>( e => e is Room );
foreach( Room room in rooms )
{
ListRoomData( room );
}
return Result.Succeeded;
}