Revit API to obtain view and document elements

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.