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: 

Tough Compound Filter

2 REPLIES 2
Reply
Message 1 of 3
JamieVJohnson
216 Views, 2 Replies

Tough Compound Filter

I have this function that runs a few filters in loops that I would like to see if they can all be combined into one call to doc.elements(filter,elementarray). First I get a list of all family symbols that have our shared parameter "UsageID". Then I cycle through all the found symbols and look for any family instance objects using one of those family symbols. To put it in straight words, I want ALL family instance type objects that have a family symbol whose parameter "UsageID" = strUsageID. Can it be done in one compound filter? Thank you in advance if you have ANY ideas or improvements.

Public Function GetFamilyInstancesByUsageID(ByVal strUsageID As String) As ElementArray

Dim eaFamSym As New ElementArray

Dim eaFamInst As New ElementArray

'run filter on family instances that are framing

Dim cf As Creation.Filter = rApp.Create.Filter

Dim fFamInst As Filter = cf.NewTypeFilter(GetType(Elements.FamilyInstance))

'run filter on family symbols that have usageID paramter of strUsageID

Dim fUsage As Filter = cf.NewParameterFilter("UsageId", Enums.CriteriaFilterType.Equal, strUsageID)

Dim fFamSym As Filter = cf.NewTypeFilter(GetType(Symbols.FamilySymbol))

Dim fFSandU As Filter = cf.NewLogicAndFilter(fUsage, fFamSym)

Dim n As Integer = doc.Elements(fFSandU, eaFamSym)

For Each fs As Symbols.FamilySymbol In eaFamSym 'cycle through all family symbols used for as a strUsageID

Dim fFamSymName As Filter = cf.NewSymbolFilter(fs.Name)

Dim fFinal As Filter = cf.NewLogicAndFilter(fFamInst, fFamSymName)

n = doc.Elements(fFinal, eaFamInst)

Next

Return eaFamInst

End Function

2 REPLIES 2
Message 2 of 3
joelkarr
in reply to: JamieVJohnson

Jamie,



If I understand correctly, you would like to minimize the calls to the document and create one filter and have a single document call?



I think you are already most of the way there. Could you move this piece to outside of the loop.



[code]

n = doc.Elements(fFinal, eaFamInst)

[/code]


Then add



[code]

//Outside of Loop

Dim fEntire as Filter;

//Inside of Loop

Dim fFinal As Filter = cf.NewLogicAndFilter(fFamInst, fFamSymName)

fEntire= cf.NewLogicOrFilter(fFinal, fEntireFilter);

[/code]



that way you will have an or statement connecting each one of your calls you were making inside the loop. The result with be the sum all of the results of the loops filters. Edited by: joelkarr on Oct 12, 2009 4:05 PM
Message 3 of 3

Forest and Tree's man!!

Thanks a bunch.

jvj

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