Create SubCategory in familiy editor

Hello,
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,

https://forum.dynamobim.com/t/add-a-subcategory-in-detail-item-family/25992

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
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import Element wrapper extension methods
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

newsubs=IN[0]

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

fam_subcats=[]

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

TransactionManager.Instance.TransactionTaskDone()

OUT=fam_subcats

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

2 Likes

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.

[newsubs]

: 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:
Line%20color

2 Likes

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

Hi your explanation is very informative and super helpful, cause I’ve been struggling with editing Subcategory too. However, I have a question, I can’t find Set SubCategory ProjectionLineweight from Genius Loci package, is it because of the version?

Hi,

The new name of this custom node is Set SubCategory Properties.

Hi thank you so much for answering my question, but I dont’t know why I can’t find it
dynamo version
it’s my Dynamo Version, do you think that it’s because of the version?

Yes, the custom nodes from the Genius Loci package are no longer available in Dynamo 1.3.4.
Download an early 2022 version.

Thank you, I’ll try it