<VB.NET>
'' Find a list of elements with given class,
name, category (optional).
Public Shared Function FindElements(ByVal rvtDoc As Document, _
ByVal targetType As Type, ByVal targetName As String, _
Optional ByVal targetCategory As BuiltInCategory = Nothing) As IList(Of Element)
'' narrow
down to the elements of the given type and category
Dim collector = _
New
FilteredElementCollector(rvtDoc).OfClass(targetType)
If Not (targetCategory = Nothing) Then
collector.OfCategory(targetCategory)
End If
'' parse the
collection for the given names. using LINQ query here.
Dim elems = _
From element In collector _
Where element.Name.Equals(targetName) _
Select element
'' put the
result as a list of element for accessibility.
Return elems.ToList()
End Function
</VB.NET>