Collect all categories in a project

Hello Dynamo community.

I’m am currently working with a project where a need to make a list of all elements in the project, with there name and classification code,

At this point I know how to do that with one category, but I would like to know if any of you knew a way , so I can select all the categories in the project.

Thank you in advance

1 Like

Hi,

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument


OUT = [i.Name for i in doc.Settings.Categories]
6 Likes

Hey Tomasz thanks for the fast replay

Wow that was effektiv

but how can i convert it so i can select all elements of those categories ?

You need to specify category and use collector:

1 Like

Hmmm can i get the collector to instead of “just” walls all the categories in the project ?

and again Thanks :slight_smile:

U can get whatever you want to:
http://revitapisearch.com/html/ba1c5b30-242f-5fdc-8ea9-ec3b61e6e722.htm

last an final question, how do i add one of those in the script ?

im a little knew i python :slight_smile:

Change line BuiltInCategory.xxx
where xxx is category from the link
OST_Walls to for example OST_Windows etc

thanks, and i can just keep on adding categories, in the same code ? :slight_smile:

I think that I’m doing it wrong hehe

walls = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
windows = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Windows)
doors = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Doors)

I still think I’m doing it wrong

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

Like Tomasz says it’s probably easier doing this with nodes:

This will also get you all annations families though. If you want to use this for take-off then you’re better of creating seperate category nodes and combining those into a single list like so:

3 Likes

The FilteredElementCollector gives you all elements in Revit, however it won’t let you access them without some kind of filter.

If you really want ALL elements in the Revit DB, you can trick the filter like this (from: http://thebuildingcoder.typepad.com/blog/2010/06/filter-for-all-elements.html)

As you can see this gives me thousands of elements in a fresh opened file from template:

import clr

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

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

doc = DocumentManager.Instance.CurrentDBDocument

coll = FilteredElementCollector( doc )
coll.WherePasses(LogicalOrFilter(ElementIsElementTypeFilter( False ),ElementIsElementTypeFilter( True )))

OUT = [e.Id for e in coll]
2 Likes

Okay thank you guys,

project is that i need all the elements used in the project, an make a control, if this elements have a certain parameter ore not, and after that see what there is written in that parameter :slight_smile:

and sorry for all the beginners python questions

Try this…

5 Likes

Thanks very very much all i got the solution i wanted and more :slight_smile: you were all a big help

I ended up using t_pover and Vikram for to different script.

1 Like

@Tomasz_Puchala

That’s not very efficient. You can do a multi category filter instead:

builtInCats = List[BuiltInCategory]()
builtInCats.Add(BuiltInCategory.OST_Doors)
builtInCats.Add(BuiltInCategory.OST_Windows)
builtInCats.Add(BuiltInCategory.OST_CeilingOpening)
builtInCats.Add(BuiltInCategory.OST_FloorOpening)
builtInCats.Add(BuiltInCategory.OST_RoofOpening)
 
filter1 = ElementMulticategoryFilter(builtInCats)

elements = FilteredElementCollector(doc).WherePasses(filter1).ToElements()
7 Likes

I know it might be frustrating to run into people that know very little coding, but at the same time where do they learn the basics if not here. I would say that its quite to the contrary: This is the forum to learn some Python basics. Of course there are others like Stack Overflow or simply picking up an online course and/or a book. Everyone learns in a different way. It’s all good mate.

10 Likes