Get all categories used in a Document list

Hi @ruben.romero the last python made by @AmolShah works as expected on Revit 2021:


Cheers

1 Like

@ruben.romero I’ve modified the code to ignore the documents that are failing:
x[0] will give you a list of document names that are causing the error.
Can you share one of the failing files if possible?

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

clr.AddReference("RevitNodes")
import Revit

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

toList = lambda x : x if hasattr(x, '__iter__') else [x]

inputdocs = toList(UnwrapElement(IN[0]))
documents = []
if inputdocs == [None]:
	documents.append(DocumentManager.Instance.CurrentDBDocument)
else:
	for inputdoc in inputdocs:
		if inputdoc.GetType().ToString() == "Autodesk.Revit.DB.RevitLinkInstance": documents.append(inputdoc.GetLinkDocument())
		elif inputdoc.GetType().ToString() == "Autodesk.Revit.DB.Document": documents.append(inputdoc)
		else: documents.append(DocumentManager.Instance.CurrentDBDocument)
		
used_cat = []
unused_cat = []
error_docs = []

for document in documents:
	cats = document.Settings.Categories
	try:
		doc_temp_used = []
		doc_temp_unused = []
		for cat in cats:
			if cat.CategoryType == CategoryType.Model or cat.CategoryType == CategoryType.Annotation:
				cate = Revit.Elements.Category.ById(cat.Id.IntegerValue)
				count = FilteredElementCollector(document).OfCategoryId(cat.Id).WhereElementIsNotElementType().GetElementCount();
				if count>0:
					doc_temp_used.append(cate)
				else:	
					doc_temp_unused.append(cate)
		used_cat.append(doc_temp_used)
		unused_cat.append(doc_temp_unused)
	except:
		error_docs.append(document.Title)		

OUT = error_docs,used_cat, unused_cat

@paris Thank you for testing it out.

1 Like

Hi @ruben.romero maybe try to verify if all your documents IN[0] are on Revit 2021
Cheers

they are all Revit 2021

It does not work, first time I read this warning type in Dynamo
image

Hi @ruben.romero can you share the RVT model 2021 and dyn file?
Cheers

not possible sorry