Create SubCategory in familiy editor

I’m new to Dynamo and i can see i will need to get better with Python nodes to achieve my goals, but i’m not even close to being a programmer…

I want to create a new subcategory of object styles using a python node to speed up the process of creating certain electric families. I saw this post,

but the creation of subcategories needs to be multiple, if i enter a single string it get decomposed as one style per letter of the string.

This is my grapgh so far

This is my python script

I’m sure it must not be so difficult to do one i understand what i’m doing better, but it’s a little bit overwhelming.

Thank you

Hi @marc.savoieTRPRP,

The original Python script iterate over a list of names and you’re not feeding a list but a singleton and it explains why the script fails.
You can add a conditional check in the python script to be sure to iterate over a list.

Another small improvement is to output the list of created subcategories.
And then the code becomes :

import clr
from Autodesk.DesignScript.Geometry import *

# Import Element wrapper extension methods
import Revit

# Import geometry conversion extension methods

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *


if not hasattr(newsubs, '__iter__'):
	newsubs = [newsubs]


for newsub in newsubs:
#create new sucategory
	fam_subcat = doc.Settings.Categories.NewSubcategory(doc.OwnerFamily.FamilyCategory, newsub)



P.S : Clockwork package already has a node for that.


Thank you. I will try that tomorrow.

@Alban_de_Chasteigner I tried it this morning and ti works fine. :smile:

I see the problem about the list, altough i don’t think i’m near understanding it all, and i missed a lot of " : " in my code. I’m not sur i understand the “Iter” thing. Does it mean that if newbubs is not in list format it uses newsubs as it is? As i said, i’m just a good Revit user trying to program some dynamo script to help in the work and being a not so good programer:no_mouth:.

Now i will try to add line color and line style to the nuw subcategory and i will be good to go.

Thank you!

I’m not a programmer either so my explanations may not be clear.


: Create a list if the input is not a list.

I’ve already a node to set the line color but this could be a good python practice for you. :grinning:

1 Like

I forgot to mention, but the reason why i can’t use categories to create subcategories is that the category changes from one electrical familly to the other. I want to have a subcategory of minimum space needed in front of the equipment in multiple family categories.

I will try to add line weight and color just like your node. I just hope it’s gonna kick in in my head soon. You know about deadlines too. :joy:

nice Node.
But it does only work in Projects.

could it also work in Family-Editor? that would be very nice. We have many Subcategorys in our Company-Families :slight_smile:
Thank you for your answer