Getting all types in the document that contains specified text

Seems like this should be easy, but I can’t quite wrap my head around it.

I need to somehow get all the elements in the document that have types containing specified text.

These elements could be Generic Annotation, Detail Items, or Dimensions.

So, first I tried collecting all elements of a category, but then Elements.Type just spits out things like “FilledRegionType” instead of the name of the type.

So, I thought, I could get all the family types first, then filter the types containing the text, then grab all elements of the remaining types. But I can’t figure out how to get all types to filter by. I also don’t really want to grab a huge data set just to filter it down to a few elements.

So, basically, I need to get ALL elements where the type name contains “X”.


I think you’re on the right path, you just need to get the Name of the Type before searching. It would also be helpful if you showed us what you’re working with.

1 Like

Yeah, not really anything so far that I’m working with since I don’t get past the first couple nodes. I feel like I can come at this from several angles. Get the type names first, filter them, then get the elements of those types (the best way since it wouldn’t be category-limited), or I could get all the elements of pre-chosen categories, get their type names, filter those names, then filter the elements based on the remaining type names.

Getting the name of the type is the beginning of the issue. I first have to get ALL types, then filter those types to see if the type name contains the text I’m looking for. But how do I get all type?

Is there some way to get all types that contain, rather than getting ALL TYPES (which I don’t know how to do either) and then filtering them?

There’s a Types node, but it makes you choose the type from a list. What node truly gets a list of all types?

The other big issue is that not all elements present their types like others. If I use All Family Types Of Category on Generic Annotations, Detail Items, and Dimensions, I get a list of actual family types, a list of some actual types and “FilledRegionType”, and an empty list, respectively.

So, I can’t cleanly get the same information for each category.

There’s no way to get all types containing a substring directly. This isn’t possible without knowing the type name, which requires you to get all the type names.

The easiest and fastest way to get all the types is with a FilteredElementCollector in the API. You can do that by category first or just straight to all types. You can do the same thing with nodes but it will be slower. You just need to go from Category to Families to Types or from all Families to Types (or the same process with Classes that don’t have FamilyTypes). There are some custom nodes that combine a few steps but you should be able to do it with ootb nodes too.

You are correct that not all elements will return their types in the same way. That’s something you just have to deal with and why I’d recommend focusing on specific categories or classes / element types that you can handle intentionally.

It’s a tad big for what it does, but it seems to work:

Nice job. You should be able to get all elements of type or all instances of family type directly, rather than searching all instances for matching types.