Get all Categories and Subcategories from a Project

I am very new in Dynamo world!
I was browsing a lot in this Forum an found (and used) some practical Python Nodes for getting all Categories and Subcategories from a Revit Project but after couple of runs the results od the Node “AllCategories in Project” ist GONE(?) and any further Nodes doesn’t work. I cannot even join and sort lists… So please, help!

I need to export all Categories and Subcategories from active Project into Exel file which I want to use later as a DWG Export Template.

What i didn’t manage (and have no idea how to) is to get two Colums in Excel (similar to Export Template). Maybe i should go for TXT with Tabstopps first… But this bothers me not so much.

and hier my Dynamo Script:

Def: AllCategoriesInProject:


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

clr.AddReference("RevitNodes")
import Revit

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument
cats = doc.Settings.Categories

used_cat = []
unused_cat = []
for cat in cats:
        #if cat.CategoryType == CategoryType.Model or cat.CategoryType == CategoryType.Annotation:
        cate = Revit.Elements.Category.ById(cat.Id.IntegerValue)
        count = FilteredElementCollector(doc).OfCategoryId(cat.Id).WhereElementIsNotElementType().GetElementCount();
        if count>0:
                used_cat.append(cate)
        else:
                unused_cat.append(cate)

OUT = used_cat, unused_cat

Def:Category.Subcategories:
Custom Clockwork Node, updated in CPython3
I think it works well!

Thank You in Advance!

Hi Natalia, welcome to the forum :person_raising_hand:

You can use markdown to add code to a post - use </> in the menu to format

Do you have IronPython 2.7 from the Package Manager installed?
image

Or try All categories in document node from MEPover package - EDIT this stops working

Try Archilab Categories.GetAll or Data-Shapes Categories list

Hi Mike,

First, thank You for your response. Now i can format the code properly! :slight_smile:

I looked at the packages and found out that i have DynamoIronPython3 installed.
What i can see is also DynamoIronPython2.7 which is not installed but has a newer date.

Do you know why is that? Should i install both?

Do you know whats the difference between IronPython3 and CPython3?
image

I’ve installed Data-Shapes and will try it out.
I couldn’t find Archilab in search, i suppose i have to look for it in Web.

I’ll keep You updated!

IronPython 2.7 and IronPython 3 are different and can both be installed at the same time

Search for archi-lab.net in the Package Manager

The basic version - CPython uses the pythonnet library to interpret .NET objects, IronPython (both flavours) is coded using .NET to integrate python

1 Like

Thank you.

I have installed Data Shapes and Archilab. Also DynamoIronPython2.7.

I tried both Nodes (Archilab and Data-Shapes) but i get nothing:/
I had to migrate one Python Skript in Categories list to CPython3
(otherwise you get an Error Notification) but it still doesn’t work.

Hi,

Thank You.

This was very enlighting:)

The Custom Node “AllCategoriesInProject” (which after couple of runs stops working) ist the first Node in a Script and its input data comes from Revit Project. Therefore I think the Problem ist not wirth an input in Dynamo. But maybe I am wrong.

Sadly i do not have admin rights to install the openpyxl.
I will check it with our IT department and keep you updated.

Export to Excel via Python look very promising! I would definitely like to do that!

Look. The Error starts already here:

Enlightening, but also very much an answer @albertrr2321 got from a LLM.

You don’t have to write your own Export node in order to achieve what you are after :slight_smile:

2 Likes

Did you get a solution for what you are looking for?

Potentially looks like there may be an issue with the file

Have you tried closing Revit, restarting and trying the graph on a different Revit file?

Try this code

import sys
import traceback

import clr

clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager

clr.AddReference("RevitNodes")
import Revit

doc = DocumentManager.Instance.CurrentDBDocument

try:
    revit_cats = sorted(doc.Settings.Categories, key=lambda c: c.Name)
    cat_names = [c.Name for c in revit_cats]
    dynamo_cats = [Revit.Elements.Category.ById(c.Id.IntegerValue) for c in revit_cats]
    
    OUT = zip(cat_names, revit_cats, dynamo_cats)
    
except:
    OUT = traceback.format_exc()
2 Likes

Thanks, I’ve tried your script but looks kind of strange…

Previously I’ve had 373 objects (categories) and your skript found 1119…
I think there my by some doubles.
Also some of them do not really get a proper name: “Autodesk.Revit.DB.Cat”

What does an orange color mean?

To answer your previous question: I’ve opend a different project (after restart) but my output (empty watch node) looked the same:/

I got also some new notifications that there is a problem with an archi-lab extention…

Well. I thought that was one easy thing which i wanted to do with dynamo but i think i’ll stuck here for a while…:smiley:

Well, if you are asking me, still looking for an answer…

The code gets all the categories in the document and returns

  • The name as a string
  • The Revit type (Autodesk.Revit.DB.Category)
  • The Dynamo type (Revit.Elements.Category) which appears the same as the string except in white text

1119 / 3 = 373

You are probably after the Dynamo type so change the OUT line to OUT = dynamo_cats

1 Like

I think i have to come back here in a couple of years and then maybe i will not ask such a stupid questions😂

Thank you Mike, i will check this out tommorow, you made my day!

1 Like