Selecting Elements by Subcategory in Family Document - Element.ByCategory

I’m working on a graph to select elements in a family and change the sub-categories and somehow managed to get it largely working, except the Element.ByCategory node from DanEDU doesn’t seem to like all of my subcategories. I’ve tried inputting the string directly as well as querying the subcategories and pulling from that list but both give a traceback error from the Element.ByCategory node.

Is there a better way to go about this or is there something wonky with the node itself?


Silly question but does the Specialty Equipment - Clearance Space Protection sub-category exist?

It seems maybe there are no elements of that particular subcategory :thinking:

If there are no elements it returns an empty list. For reference - here is a small test family that has an object on the Clearance-Space Protection sub category, and one on the Laundry sub category.

ObjectSubCategoryTest.rfa (432 KB)

After some additional testing, it seems the dash in the name is causing the error… Clearance Space Protection works, Clearance-Space Protection does not work :thinking:

edit: underscore works though… Could this be related to the issues Revit has when using operators in parameter names?

@erfajo Thanks for the update. I’m not totally up on the programming side of things but I think I generally get what you are saying. Where is that section of code in your node? I opened the node itself and didn’t see anything.

I did a little more tinkering and it seems like the dash, and sometimes spaces, in the subcategory name are causing the error. Oddly Clearance_Space Protection does not throw any errors. Wondering if I could just rename the subcategories temporarily for processing…

@Chad_Clary I’m not sure if spaces is an issue - it looks like you have a typo (missing the e in Clearance) for the last subcategory name formatting you tried. You might not have to do too much renaming if that’s the case. Also the Python scripts for @erfajo’s package are found in wherever your package path is\DanEDU Dynamo\extra\lib

1 Like

Nice catch! That cleared up the issue with the last input, meaning the error is related to the dash, which sucks - because I have a lot of them…
And thanks for the info on where the Python is. Learned something new!

@Chad_Clary this is sort of a separate topic, but since you’re already developing a workflow to modify family geometries’ sub-categories, perhaps you can recreate the subcategories like this:

(all custom nodes are Clockwork except for Springs.Doc.DeleteElements)

EDIT - might be safer to filter for only the subcategories that have dashes in their names, so you don’t end up recreating every single subcategory

EDIT EDIT - In retrospect, probably not the best idea. Probably would mess up things on the project side (view templates, etc.). Not certain though.

1 Like

Thanks, I’ll see what I can do with it. I was in the process of trying to figure out how to rollback changes as-is…

My end goal with this is to clean up families, taking all the various permutations of subcategories that currently exist (Clearance, clearance, Clearances, etc) and swap them all into one consistent subcategory, so in the long-term it will help projects & templates, although there will be some awkward teenage years during the transition. I already have a graph to nuke subcategories, removing everything except the few that I want, but being able to fix it without manually going through every family I have would be kind of awesome.


1 Like

Got it working! at least at the moment
2 versions of the graph below; they use slightly different methods to get everything and process it. One version uses the methods in this thread, albeit sloppily; V2 reuses some code from the delete subcategories graph I put together earlier (found here.)
The updated version to set subcategories does rely on the Element.SetSubCategory node from Clockwork that is currently only in the Git repository. Thread discussing it here: Reassigning subcategories

Next step will be to figure out which one will work best long-term and clean them up.

Thanks for all the help! :beer: is on me. :beers:


Family-SetObjectSubcategory.dyn (27.5 KB)
Family-SetObjectSubcategoryV2.dyn (25.7 KB)


It definitely needs cleaning up. The version posted was as much joy over the fact that it works as anything.

The big list is subcategories that I want (not sure if I clarified that earlier), so changing the Clearance lines doesn’t work - although the formatting change is a nice touch. I will definitely be implementing that elsewhere :metal:

I also really appreciate the additional versions. I restructured some to align with the V3 that you posted. At the moment I’m not using the Python so I can actually figure out what I did when i go back to modify this 6 months from now, but figuring Python out is on my list of things to do.

Thanks again! :beers:

1 Like

Hello community,

I still dont understand how I can select families from a subcategory, or how I can get the subcategory/subcategories of a family typ or instance.

Categories und Subcategorien_03.dyn (10.6 KB)