Revit API获得视图与文档中的元素
文档中的元素与视图下的元素数量是不同的。
比如即使一个墙没画文档中也包含6个Wall
from:http://revit.5d6d.com/thread-1291-1-1.html
比如即使一个墙没画文档中也包含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());
}
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。