Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Quickest method to get familyinstances from a list of families in a project

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
1335 Views, 3 Replies

Quickest method to get familyinstances from a list of families in a project

If I already have a list of Families and I want to iterate through all the familyinstances, what is the quickest way to get a a list in a collector.

 

so for each family...I iterate and call a method with this filtered element collector, which is very slow on a large project. Should i get the family symbols first for each family and use a where(family symbol has name...)

Also could i send the category first to reduce the time, I will check these myself I was just wondering if their are any major flaws in my approach?

 

foreach
(
FamilyInstance fi in new FilteredElementCollector(_doc)
.OfClass(typeof(FamilyInstance))
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Cast<FamilyInstance>()

.Where(f => f.HasPhases() == true)
.Where(f => f.Name == _family.Name)

)
{

//do something with family instances

}

3 REPLIES 3
Message 2 of 4
jeremytammik
in reply to: Anonymous

That is an interesting question.

 

If you really want optimal speed in a large project with many instances, you will have to convert your LINQ Where<> clauses into something that can be run inside Revit by the filtered element collector itself.

 

As your code stands now, you are retrieving all data of all family instances and post-processing the result with Where<>.

 

If you eliminate the data retrieval and marshalling across from internal Revit memory to external add-in .NET memory, you will increase performance by at least 50 percent and maybe much more, cf.

 

http://thebuildingcoder.typepad.com/blog/2015/12/quick-slow-and-linq-element-filtering.html

 

Normally, the best alternative to the post-processing is to implement one or more parameter filters.

 

In this case, you could:

 

  • Identify which parameter on the instance identifies the family. It is probably an ElementId.
  • For each family your are interested in retrieving instances form, create an ElementId-equals parameter filter.
  • Create a logical OR of all those different element-id-equals-specific-family filters.
  • Apply that filter.

 

Et voila. That should provide the optimal solution.

 

Look here for further info:

 

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

 

Please benchmark the solution you have right now.

 

Then, implement the suggestion above, benchmark that as well, and share your code and results.

 

That would be very nice of you!

 

Thank you!

 

Cheers,

 

Jeremy

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 4
Anonymous
in reply to: jeremytammik

Thanx for your advice Jeremy

I have modified my code to use the parameterFilters in 3 different methods that each use one or more collectors for filtered elements, I found how to do this one of your posts on parameter filters very nice post, personally I find them ugly to look at however that is not what it's all about. So I will in the future apply a timer, If I log some data do you want to see the difference between each method or just the overall time to completion of say a button event?

Message 4 of 4
jeremytammik
in reply to: Anonymous

Dear Phil,

 

Both, please, if it is not too much bother.

 

Looking forward to seeing the results and a sample code snippet.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community