Revit API过滤元素类别(FamilySymbol与FamilyInstance)

仅OfCategory()过滤的元素包含系统FamilySymbol
OfClass(typeof(FamilyInstance))过滤出来文档中族实例。
//过滤元素类别
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdGetCate : IExternalCommand
{
    public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
    {
        UIDocument uiDoc = cmdData.Application.ActiveUIDocument;

        Transaction ts = new Transaction(uiDoc.Document, "SetFamily");
        ts.Start();

        FilteredElementCollector collector = new FilteredElementCollector(uiDoc.Document);
        collector.OfCategory(BuiltInCategory.OST_DuctFitting);//过滤出来系统包含的Symbol与文档包含的Instance
        
//collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_DuctFitting);
        int iSymbol = 0;
        int iFi = 0;
        foreach (Element el in collector)
        {
            if (el is FamilySymbol)
                iSymbol += 1;
            else if (el is FamilyInstance)
                iFi += 1;
        }
        TaskDialog.Show("count", iSymbol + "," + iFi);

        ts.Commit();

        return Result.Succeeded;
    }
}
url:http://greatverve.cnblogs.com/p/api-get-symbol-instance.html
posted @ 2013-10-31 13:32  大气象  阅读(3457)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com