what is good solution to get element list

what is good solution to get element list

Anonymous
Not applicable
1,077 Views
3 Replies
Message 1 of 4

what is good solution to get element list

Anonymous
Not applicable

I want to get element list kind of electrical.

 

In electrical filter, there is so many categories..

 

 

Cable Tray Fittings, Cable Tray Runs, Cable Trays ..and so on.

 

whiat is good solution to get element list of these categories?

0 Likes
Accepted solutions (2)
1,078 Views
3 Replies
Replies (3)
Message 2 of 4

Joe.Ye
Alumni
Alumni
Accepted solution

 

Hello,

 

You can use the logical filter to union those electrical related category filters. And then get all those elements list from the FilteredElementCollector.

 

The steps is like this. I didnot test the code. Replace the right category here in the first couple of lines.

 

<code>

public IList<Element> GetElectricalElements(Document doc)

{

   ElementCategoryFilter catFilter1 = new ElementCategoryFilter(BuiltInCategory.OST****);

   ElementCategoryFilter catFilter2 = new ElementCategoryFilter(BuiltInCategory.OST****);

   ElementCategoryFilter catFilter3 = new ElementCategoryFilter(BuiltInCategory.OST****);

   ElementCategoryFilter catFilter4 = new ElementCategoryFilter(BuiltInCategory.OST****);

   ElementCategoryFilter catFilter5 = new ElementCategoryFilter(BuiltInCategory.OST****);

    //create more filter here as needed.

 

   IList<ElementFilter> list = New List<ElementFilter>();

  

   list.Add(catFilter1);

   list.Add(catFilter2);

   list.Add(catFilter3);

   list.Add(catFilter4);

   list.Add(catFilter5);

  //add more to the list here.

 

   LogicalOrFilter orFilter = new LogicalOrFilter(list);

 

    FilterElementCollector collector  = new FilterElementCollector(doc);

    collector.WherePasses(orFilter);

 

    IList<Element> elementList = collector.ToElements();

 

}

<code>



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 4

conoves
Autodesk
Autodesk
Accepted solution

It is also possible to encapsulate a list of categories with an ElementMulticategoryFilter (instead of a LogicalOrFilter joining multiple category filters).  The results should be the same but slightly less code to write.



Scott Conover

Senior Engineering Manager, Revit

Message 4 of 4

Joe.Ye
Alumni
Alumni

cool, more simple!



Joe Ye
Contractor
Developer Technical Services
Autodesk Developer Network
0 Likes