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
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
edit: underscore works though… Could this be related to the issues Revit has when using operators in parameter names?
Sorry for being late in this reply.
@Chad_Clary it is a very interesting way you use my node. I must admit that I have never thought of the idea getting subcategories and thats why you cant get those as such. why it then works in one instance is a mystery for me. In my code I only get the ’BuiltInCategory’ as shown below.
if isinstance(cat, basestring):
cat = Category.ByName(cat)
If you take a look at the code behind the Clockwork (@Andreas_Dieckmann) node, then Andreas get the ‘SubCategories’ as shown below
for subcat in cat.SubCategories:
The idea to use the Clockwork node makes it a valid feed, since that output is a category. Using text string is what I change with my code as show above… and that is not subcategories.
I don’t know how I can secure that only BuiltInCategory is accepted when clearly you can succeed with getting a subcategory that should fail. the node Category.ByName shows that it is a problem somewhere in that node.
Home.dyn (6.9 KB)
@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
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.
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.
As @awilliams wrote, all my code is kept outside the nodes in the lib folder (extra/lib). I only use the nodes as placeholders for the code because I have changed my entire package into an OOP environment consisting of py files in a folder structure.
The code can be found in the filename for this node in the purple box.
This line of code -->
cat = Category.ByName(cat)
<-- is doing the same as the node which has the “problem” of accepting some strings and not others. So your test has been interesting for me to see since I did not have this usage in my mind when I coded it.
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! is on me.
Family-SetObjectSubcategory.dyn (27.5 KB)
Family-SetObjectSubcategoryV2.dyn (25.7 KB)
I am convinced that you could optimize this further… search only once for what you need, dont do it twice in a row. and what is computed once, reuse that many time.
Family-SetObjectSubcategoryV3.dyn (17.4 KB)
but with a bit of coding…
Family-SetObjectSubcategoryV4.dyn (11.4 KB)
and then condense it even more…
Family-SetObjectSubcategoryV5.dyn (9.0 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
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.
take the time you need. the version 3 and 4 is doing the same, so now where you have it, you can go back at any time
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
please start a new post with your topic. You can refer to old topic in new topics.