Collect all categories in a project

Hey Konrad,

what should I wright i OUT = ??? to get the list out with your code ?

OUT = elements

1 Like

I think I’m maybe starting the script the wrong way

What’s your error?

IronPythonEvaluator.EvaluateIronPythonScript
operation failed.
Traceback (most recent call last):
File “”, line 16, in
NameError: name ‘List’ is not defined

:slight_smile:

You need a reference for Collections.Generic. Try this:

from System.Collections.Generic import *

That kinda worked, now there is not a fail but the list is empty

you probably want this as well. This will wrap Revit API elements into Dynamo

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

Also do you have doors in that project? I mean, this is a multi category element collector not a Category collector. It returns all elements of category. I would actually propose you use the OOTB noes for this and a method that @T_Pover suggested. It’s not different.

okay so the node called get Categories with builtins would be the one to use ? and thanks again for all the help :slight_smile:

1 Like

Just getting every model category in the model bothered me for a while as well, so I finally got this working:

5 Likes

I just feed the desired Built in category names to my super collect node, not all of them.

Sure, it’s part of my package: MEPover

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

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

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

model_cat = []
anno_cat = []
ana_cat = []
internal_cat = []

for c in categories:
	if c.CategoryType == CategoryType.Model:
		model_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
	elif c.CategoryType == CategoryType.Annotation:
		anno_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
	elif c.CategoryType == CategoryType.AnalyticalModel:
		ana_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
	elif c.CategoryType == CategoryType.Internal:
		internal_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
		

OUT = model_cat, anno_cat, ana_cat, internal_cat

Please note, I refrained from using ‘anal_cat’ :slight_smile:

11 Likes

That is indeed true. The API documentation also mentions this: "The category type determines if the category is shown in the Visibility/Graphics settings grouped with the model,annotation, or analytical model categories. Note that import categories are also “model” but will be shown separately in the dialog. Some categories not shown in the dialog and will return Internal for the category type."
I don’t know if there’s a way to filter it besides a string comparison.

I guess you could narrow it down a bit further like this:

for c in categories:
	if c.CategoryType == CategoryType.Model:
		if c.SubCategories.Size > 0 or c.CanAddSubcategory:
			model_cat.append(Revit.Elements.Category.ById(c.Id.IntegerValue))
		else:
			continue

Hi,

I dont know anything about this but has MaterialVolume seems plausible to me.
I know this is a field in the revit database exported using DBLink.

Marcel

I tried the HasMaterialQuantities property as well, but that will omit a lot of categories that are actually part of the model categories.

Now what if we wanted to save all these out to a folder?

Working through the solutions provided I am unable to find and access the RVT Links built-in category which (hopefully) would allow access to the reference Revit models in the project and begin creating associations across models. The warning in Dynamo is this:

Warning: Category.ByName operation failed. 
The selected category is not valid in this document.

I’m curious what would make a category ‘valid’ ? The only thing that comes to mind is that the underlying code of Revit disallows access to Revit Links through the API at this time. I realize the API can only go so far and hinges on what the engineers at Autodesk reveal to us common folk in the API.
Thoughts?

You can collect them.

in c# it is something like this:

        var linkColl= new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
        linkColl.OfClass(typeof(RevitLinkInstance));
        var elements = linkColl.ToElements();
1 Like