How to filter all created elements in Doc?

How to filter all created elements in Doc?

SimonaQQ
Advocate Advocate
1,287 Views
6 Replies
Message 1 of 7

How to filter all created elements in Doc?

SimonaQQ
Advocate
Advocate

Hello,

For example, only one wall has been created in my new project. I want to obtain this wall. Generally speaking, for this wall, I will directly filter out this wall by using methods such as ofclass or ofcategory, but now if I don't know whether the elements in this project are a wall, window or others, how can I obtain all these created elements?

The following code is effective for a view, but it will filter out a lot of other contents only for doc.
So do you have a better way?
thank you

            FilteredElementCollector collectorAll = new FilteredElementCollector(doc, doc.ActiveView.Id);
            var eles = collectorAll.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true))).ToList();

 

0 Likes
1,288 Views
6 Replies
Replies (6)
Message 2 of 7

Omar_Amen
Advocate
Advocate

Hi @SimonaQQ ,
If all what do you need is just to get all the element in the document not only the visible elements in a single view,
so you can use the same code after removing the view argument from the FilteredElementCollector Constructor
and remove the elements that has no category or location to reduce the unwanted object in the result then it will look like :

 

FilteredElementCollector collectorAll = new FilteredElementCollector(doc);
var eles = collectorAll.WherePasses(new ElementIsElementTypeFilter(true)).Where(e => e.Category != null && e.Location != null ).ToList();

 

is this what do you want to achieve ?

0 Likes
Message 3 of 7

jeremy_tammik
Alumni
Alumni

Look here at the section on retrieving newly created elements:

  

https://thebuildingcoder.typepad.com/blog/2010/06/place-family-instance.html

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 4 of 7

SimonaQQ
Advocate
Advocate
I tried. There will still be many other elements, but it is understandable. After all, many elements will be created automatically when doc is created.
Thank you very much
0 Likes
Message 5 of 7

SimonaQQ
Advocate
Advocate
Thank you.
Maybe I didn't make it clear.
What I want is to get all the elements in the doc, but not those automatically created by the project.
For example, if there is only one wall in a project, I want to get only this wall.
That's what I mean.
thank you.
0 Likes
Message 6 of 7

SimonaQQ
Advocate
Advocate
My idea is mainly to empty all contents in the family doc when editing the family, or restore the family. Or is there any other way to clear the family doc or restore it?
0 Likes
Message 7 of 7

jeremy_tammik
Alumni
Alumni

Yes, indeed, you did not make yourself clear, and I am still uncertain what exactly you need.

 

One. very common requirement that has been discussed many times in the past is to retrieve all true physical BIM elements, everything representing bits and pieces of the building that you can actually see and touch and measure.

 

Several different approaches to retrieve all Model Elements or Visible 3D Elements have been discussed by The Building Coder:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes