The number of elements in the document is different from that in the view.
For example, even if a wall is not drawn, it also contains 6 walls. Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
UsingWinform=System. Windows. forms;
UsingAutodesk. revit. UI;
UsingAutodesk. revit. dB;
UsingAutodesk. revit. attributes;
UsingAutodesk. revit. DB. Mechanical;
UsingAutodesk. revit. UI. selection;
UsingAutodesk. revit. applicationservices;
UsingAutodesk. revit. DB. structure;
UsingAutodesk. revit. DB. extensiblestorage;
using system. XML;
namespace revitcodes
{< br> [transactionattribute (Autodesk. revit. attributes. transactionmode. manual)]
Public class lateral view: iexternalcommand
{< br> Public result execute (externalcommanddata commanddata, ref string messages, elementset elements)
{
Uiapplication app=Commanddata. Application;
Document Doc=App. activeuidocument. Document;
Countelements (DOC );
Return Result. succeeded;
}
// The number of elements contained in the view and the entire document is different.
Private Void Countelements (document DOC)
{
Stringbuilder msg = New Stringbuilder ();
Filteredelementcollector viewcollector = New Filteredelementcollector (Doc, doc. activeview. ID );
Viewcollector. ofcategory (builtincategory. ost_wils );
MSG. appendline ( " Wall within active View: " + Viewcollector. toelementids (). Count );
Filteredelementcollector doccollector = New Filteredelementcollector (DOC );
Doccollector. ofcategory (builtincategory. ost_wils );
MSG. appendline ( " Wall within document: " + Doccollector. toelementids (). Count );
Taskdialog. Show ( " Http://revit.5d6d.com " , MSG. tostring ());
}
}
}
From: http://revit.5d6d.com/thread-1291-1-1.html