Filtered |
Exception | Condition |
---|---|
ArgumentException | viewId is not a view. -or- viewId is not valid for element iteration, because it has no way of representing drawn elements. Many view templates will fail this check. |
ArgumentNullException | A non-optional argument was null |
Elements that will be passed by the collector have graphics that may be visible in the input view. Some elements may still be hidden because they are obscured by other elements.
For elements which are outside of a crop region, they may still be passed by the collector because Revit relies on later processing to eliminate the elements hidden by the crop. This effect may more easily occur for non-rectangular crop regions, but may also happen even for rectangular crops. You can compare the boundary of the region with the element's boundary if more precise results are required.
Accessing these visible elements may require Revit to rebuild the geometry of the view. The first time your code constructs a collector for a given view, or the first time your code constructs a collector for a view whose display settings have just been changed, you may experience a significant performance degradation.
private void CountElements(UIDocument uiDoc) { StringBuilder message = new StringBuilder(); FilteredElementCollector viewCollector = new FilteredElementCollector(uiDoc.Document, uiDoc.ActiveView.Id); viewCollector.OfCategory(BuiltInCategory.OST_Walls); message.AppendLine("Wall category elements within active View: " + viewCollector.ToElementIds().Count); FilteredElementCollector docCollector = new FilteredElementCollector(uiDoc.Document); docCollector.OfCategory(BuiltInCategory.OST_Walls); message.AppendLine("Wall category elements within document: " + docCollector.ToElementIds().Count); TaskDialog.Show("Revit", message.ToString()); }
public static void GetScheduleContents(ViewSchedule viewSchedule) { // Collect types displayed in the schedule FilteredElementCollector typeCollector = new FilteredElementCollector(viewSchedule.Document, viewSchedule.Id); typeCollector.WhereElementIsElementType(); int numberOfTypes = typeCollector.Count(); // Collect instances displayed in the schedule FilteredElementCollector instCollector = new FilteredElementCollector(viewSchedule.Document, viewSchedule.Id); instCollector.WhereElementIsNotElementType(); int numberOfInstances = instCollector.Count(); TaskDialog.Show("Elements in schedule", String.Format("Types {0} instances {1}", numberOfTypes, numberOfInstances)); }