比如即使一个墙没画文档中也包含6个Wall
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
CountElements(doc);
return Result.Succeeded;
}
// 视图中包含和的元素和整个文档包含的元素数量是不同的。
private void CountElements(Document doc)
{
StringBuilder msg = new StringBuilder();
FilteredElementCollector viewCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);
viewCollector.OfCategory(BuiltInCategory.OST_Walls);
msg.AppendLine( " Wall within active View: " + viewCollector.ToElementIds().Count);
FilteredElementCollector docCollector = new FilteredElementCollector(doc);
docCollector.OfCategory(BuiltInCategory.OST_Walls);
msg.AppendLine( " Wall within Document: " + docCollector.ToElementIds().Count);
TaskDialog.Show( " http://revit.5d6d.com " , msg.ToString());
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinForm = System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.ExtensibleStorage;
using System.Xml;
namespace RevitCodes
{
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class cmdView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
CountElements(doc);
return Result.Succeeded;
}
// 视图中包含和的元素和整个文档包含的元素数量是不同的。
private void CountElements(Document doc)
{
StringBuilder msg = new StringBuilder();
FilteredElementCollector viewCollector = new FilteredElementCollector(doc, doc.ActiveView.Id);
viewCollector.OfCategory(BuiltInCategory.OST_Walls);
msg.AppendLine( " Wall within active View: " + viewCollector.ToElementIds().Count);
FilteredElementCollector docCollector = new FilteredElementCollector(doc);
docCollector.OfCategory(BuiltInCategory.OST_Walls);
msg.AppendLine( " Wall within Document: " + docCollector.ToElementIds().Count);
TaskDialog.Show( " http://revit.5d6d.com " , msg.ToString());
}
}
}