文档中的元素与视图下的元素数量是不同的。
比如即使一个墙没画文档中也包含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());
        }
    }

}
from:http://revit.5d6d.com/thread-1291-1-1.html

相关文章:

  • 2021-12-21
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2019-12-02
  • 2022-12-23
猜你喜欢
  • 2022-02-03
  • 2022-12-23
  • 2021-10-15
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案