Revit API

Distinguished Contributor
Posts: 136
Registered: ‎09-29-2008
Message 1 of 3 (112 Views)

Tough Compound Filter

112 Views, 2 Replies
10-09-2009 02:02 PM

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)


Return eaFamInst

End Function

Active Contributor
Posts: 30
Registered: ‎11-25-2008
Message 2 of 3 (112 Views)

Re: Tough Compound Filter

10-12-2009 09:05 AM in reply to: JamieVJohnson

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.


n = doc.Elements(fFinal, eaFamInst)


Then add


//Outside of Loop

Dim fEntire as Filter;

//Inside of Loop

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

fEntire= cf.NewLogicOrFilter(fFinal, fEntireFilter);


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
Distinguished Contributor
Posts: 136
Registered: ‎09-29-2008
Message 3 of 3 (112 Views)

Re: Tough Compound Filter

10-12-2009 09:07 AM in reply to: JamieVJohnson
Forest and Tree's man!!

Thanks a bunch.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.