All elements in a active view

All elements in a active view

Anonymous
Not applicable
7,370 Views
3 Replies
Message 1 of 4

All elements in a active view

Anonymous
Not applicable

Hi!

How can I get all the elements of all categories available in a active view? Must I use a filteredCollectorElement?

0 Likes
Accepted solutions (1)
7,371 Views
3 Replies
  • API
Replies (3)
Message 2 of 4

lukaskohout
Advocate
Advocate
Accepted solution

Yes.

It is the best way to collect the elements from any document. You can directly pass the ActiveView.Id to the FilteredElementCollector overload to collect only elements visible in that view.

var col = new FilteredElementCollector(doc, doc.ActiveView.Id).   
   Cast<Element>().
   ToList();

Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
Message 3 of 4

TEK1
Participant
Participant

For anyone reading this in future sometimes you might want to add a filter (I know that I did).

 

For example, here is a snippet i ripped out from an addin i was developing.

 

 

FilteredElementCollector filter = new FilteredElementCollector(doc, doc.ActiveView.Id);

var filteredDimensions = filter.WherePasses(new ElementClassFilter(typeof(Dimension)))  
      .ToElements()
      .Cast<Dimension>()
      .Where(d => dimensionIsGood(d))

// we can filter IN dimensions
// and filter out via any condition we want

 

 

 

 

0 Likes
Message 4 of 4

karim_mostafaVM84V
Explorer
Explorer

it throw an Exception if View is of type ViewSheet

 

 

regards

karim Abdelrazek 

karim_mostafaVM84V_0-1739969864817.png

 

0 Likes