Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

revit-element-collector

/revit-element-collector

Wykonuje zapytania do modelu Revit przez opakowania FilteredElementCollector, filtrując parametrami zamiast LINQ po załadowanych elementach.

Repozytorium
revit-skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
08.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 08.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Wykonuje zapytania do modelu Revit przez opakowania FilteredElementCollector, filtrując parametrami zamiast LINQ po załadowanych elementach.

Oryginalny opis (EN)

Query the Revit model with the Nice3point.Revit.Extensions fluent FilteredElementCollector wrappers; filter with Revit's parameter filters, not by loading elements and filtering with LINQ. USE FOR: writing or reviewing element queries that filter by class, category, or parameter value and return the first match, a count, or the full set. DO NOT USE FOR: reading or setting parameters on an element already retrieved (use revit-element-and-parameter-access).

Jak działa

  1. When to use
  2. When not to use
  3. Workflow
  4. Validation
  5. Common Pitfalls
Sekcje z nagłówków SKILL.md, w oryginale · 108 linii, 597 słów
Podgląd SKILL.md
---
name: revit-element-collector
description: >
  Query the Revit model with the Nice3point.Revit.Extensions fluent FilteredElementCollector wrappers; filter with Revit's parameter filters, not by loading elements and filtering with LINQ.
  USE FOR: writing or reviewing element queries that filter by class, category, or parameter value and return the first match, a count, or the full set.
  DO NOT USE FOR: reading or setting parameters on an element already retrieved (use revit-element-and-parameter-access).
license: MIT
---

# Revit Element Collector

Query the model through the fluent `FilteredElementCollector` wrappers in `Nice3point.Revit.Extensions`.
They wrap the raw Revit collector API into a single readable chain and run the filtering inside Revit's native database engine.
The database engine evaluates the filters before elements expand into memory.
Filtering the collector output with LINQ materializes every element first.

## When to use

- Retrieving elements, types, or instances by class, category, or parameter value.
- Reviewing code that writes `new FilteredElementCollector(document)` by hand or filters collector output with `.Where(...)`.
- Fetching the first match or a count without loading the whole result set.

## When not to use

- Reading or setting parameters on an element already retrieved — use `revit-element-and-parameter-access`.
- Applying a specialized `ElementFilter` the extensions do not expose — fall back to a raw `FilteredElementCollector` with that filter.

## Workflow

Always prefer the built-in methods of `FilteredElementCollector` extensions over using LINQ.
LINQ materializes and marshals every element into the .NET process's memory and does not filter at the database level.
Use LINQ only when the built-in methods are insufficient for filtering.

### Step 1: Open a collector from the document

```csharp
var collector = document.CollectElements(); // whole document
var viewScoped = document.CollectElements(view); // elements visible in a view
var restricted = document.CollectElements(elementIds); // a known id set
```

### Step 2: Apply quick filters as generic, typed calls

Prefer the generic and multi-argument overloads over raw `typeof` filters.

```csharp
var walls = document.CollectElements()
    .OfClass<Wall>()
    .ToElements();

var openings = document.CollectElements()
    .OfCategories(BuiltInCategory.OST_Walls, BuiltInCategory.OST_Floors)
    .Instances() // only instances; use .Types() for element types
    .ToElements();

var annotated = document.CollectElements()
    .WithExtensibleStorage(schemaGuid) // elements that store add-in data
    .ToElements();
```

### Step 3: Filter by parameter with native rules, not LINQ

`WhereParameter` builds a native `ElementParameterFilter` — evaluated at the database level before element expansion — then continues the collector chain.

```csharp
var tallWalls = document.CollectElements()
    .OfClass<Wall>()
    .WhereParameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).IsGreaterThan(3.0, 1e-6)
    .ToElements();
```

```csharp
// BAD — loads every wall into memory, then filters
var tallWalls = new FilteredElementCollector(document)
    .OfClass(typeof(Wall))
    .Cast<Wall>()
    .Where(wall => wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble() > 3.0);
```

Comparisons include `Equals`, `IsGreaterThan`/`IsGreaterThanOrEqualTo`, `IsLessThan`/`IsLessThanOrEqualTo` (with an optional `double` epsilon), `Contains`/`StartsWith` (and their `Not…` inversions), and `HasValue`.

### Step 4: Terminate with the fast native path

Use the extension terminators, not LINQ.
The terminators call Revit's native fast implementations, and `Count()` calls `GetElementCount()`.

```csharp
var firstRoom = document.CollectElements().OfClass<SpatialElement>().FirstOrDefault();
var wallCount = document.CollectElements().OfClass<Wall>().Count();
var hasLevels = document.CollectElements().OfClass<Level>().Any();
```

### Step 5: Verify

1. The query builds the filter through collector methods, not `.Where(...)` over materialized elements.
2. A parameter comparison uses `WhereParameter`, not a post-collection predicate.
3. The terminator is a native call (`ToElements`, `First`, `FirstOrDefault`, `Count`, `Any`).

## Validation

- [ ] The collector comes from `document.CollectElements(...)`, not a hand-written `new FilteredElementCollector(...)`.
- [ ] Class and category filters use the generic/multi-argument extensions.
- [ ] Parameter conditions use `WhereParameter(...)`, filtering at the database level.
- [ ] Single-result and count queries use `First`/`FirstOrDefault`/`Count`/`Any`, not LINQ.
- [ ] A quick filter (class/category) precedes a slow filter (parameter) to shrink the candidate set.

## Common Pitfalls

| Pitfall                                                                            | Correct approach                                                            |
|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `.Where(element => element.get_Parameter(...).AsDouble() > x)` after the collector | `WhereParameter(param).IsGreaterThan(x, epsilon)` — a native rule.          |
| `collector.ToElements().Count` / `.Any()` (LINQ over the list)                     | `collector.Count()` / `collector.Any()` — native fast paths.                |
| Comparing `double` parameters without an epsilon                                   | Use the `IsGreaterThan(value, epsilon)` overload.                           |
| `CollectElements` or `WhereParameter` not found                                    | The `Nice3point.Revit.Extensions` package is not referenced in the project. |
| Reusing one collector after a terminator                                           | Start a fresh `CollectElements()` per query; terminators stop the iterator. |

Wersje

W bazie nie ma innych skilli o nazwie revit-element-collector.

Migawka bazy z 13.11.2026 · wersja paczki f689535d9c21 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100revit-element-and-parameter-access
    Odczytuje i zapisuje elementy oraz parametry Revit przez płynne akcesory Nice3point.Revit.Extensions, z konwersją jednostek wewnętrznych.
  • 100revit-utils-extensions
    Zastępuje statyczne wywołania narzędzi Revit i ręczne konwersje wartości płynnymi rozszerzeniami Nice3point.Revit.Extensions.
  • 90revit-ai-test-automation
    Prowadzi asystenta AI przez tworzenie i uruchamianie testów wtyczek Revit na Windows, od scenariuszy po regresję w kopii modelu.
  • 82p6-revit-4d
    Łączy harmonogram Primavera P6 (XER) z elementami modelu Revit i zapisuje go jako wymiar 4D, z widokami budowy.
  • 98open-point-cloud
    Podpina chmury punktów PLY i E57 do modelu Revit przez dodatek Open Point Cloud, z poziomu agenta lub skryptu.
  • 91csharp-linq
    Opisuje zapytania LINQ w składni zapytań i metod, odroczone wykonanie i optymalizację wydajności przy przeszukiwaniu kolekcji w C#.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.