# Get all Categories and Subcategories from a Project

**URL:** <https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190>\
**Category:** Revit\
**Created:** [January 16, 2024, 1:07pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190 "2024-01-16T13:07:48Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 16, 2024, 1:07pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/1 "2024-01-16T13:07:48Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/3/b3d56e88204512844d0731f6912bf4eda121c026.png)

Def: AllCategoriesInProject:

* * *

```auto
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!

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [January 17, 2024, 5:30am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/2 "2024-01-17T05:30:30Z")

</div>

Hi Natalia, welcome to the forum 🙋

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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/b/2b26e0c7421b90675bdc0e3ef2eb877be3afc591.png)

Or try _All categories in document_ node from MEPover package - EDIT this stops working

Try Archilab _Categories.GetAll_ or Data-Shapes _Categories list_

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 17, 2024, 9:39am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/3 "2024-01-17T09:39:12Z")

</div>

Hi Mike,

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

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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/a/3af716b47de48ad1197e6882e10a03cfef32f97f.png)

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!

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [January 17, 2024, 9:58am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/4 "2024-01-17T09:58:12Z")

</div>

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

Search for [archi-lab.net](http://archi-lab.net) in the Package Manager

> [@natalson](#):
>
> Do you know whats the difference between IronPython3 and CPython3?

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

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 17, 2024, 12:15pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/6 "2024-01-17T12:15:36Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/a/6a28e9dd2e1aca1a302da54bfbe97d52b536d246.png)

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 17, 2024, 12:29pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/7 "2024-01-17T12:29:05Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 17, 2024, 12:31pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/8 "2024-01-17T12:31:25Z")

</div>

Look. The Error starts already here:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/2/227ee6be4d1282749b731d947fdb33c7ff88d677.png)

---

<div class="post-metadata">

**Author:** ![MartinSpence](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/martinspence/32/25208_2.png) [@MartinSpence](https://forum.dynamobim.com/u/MartinSpence)\
**Post date:** [January 17, 2024, 12:40pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/9 "2024-01-17T12:40:10Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![ruben.romero](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ruben.romero/32/115842_2.png) [@ruben.romero](https://forum.dynamobim.com/u/ruben.romero)\
**Post date:** [January 17, 2024, 8:43pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/10 "2024-01-17T20:43:17Z")

</div>

> [@MartinSpence](#):
>
> an answer

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

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [January 18, 2024, 12:13am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/11 "2024-01-18T00:13:26Z")

</div>

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

```python
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()

```

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 18, 2024, 11:44am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/12 "2024-01-18T11:44:31Z")

</div>

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”

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/8/1815fae7beb721f7d9f4270e92954381711538d7.png)

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](https://forum.dynamobim.com/t/revit-2022-dynamo-2-10-package-not-showing-up-and-icons-missing/62933/7?) 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…😃

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 18, 2024, 11:45am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/13 "2024-01-18T11:45:01Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/c/0c4d68e7d6cdf654c1dfd86ae28d1133364b43b9.png)

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 18, 2024, 11:46am UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/14 "2024-01-18T11:46:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [January 18, 2024, 1:08pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/15 "2024-01-18T13:08:51Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![natalson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/natalson/32/175383_2.png) [@natalson](https://forum.dynamobim.com/u/natalson)\
**Post date:** [January 18, 2024, 1:30pm UTC](https://forum.dynamobim.com/t/get-all-categories-and-subcategories-from-a-project/97190/16 "2024-01-18T13:30:27Z")

</div>

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!
