Threedimensional list with Python

Hi,

The goal would be a list with these levels: Document > Warning > Failing Elements
Like this:
image

I managed it so far:

import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')

from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager

Docs = UnwrapElement(IN[0])

all_warns = []
all_elements = []
for Doc in Docs:
	warns = Doc.GetWarnings()
	ids = []
	all_warns.append(warns)
	for warn in warns:
		ids = warn.GetFailingElements()
		elements = []
		for id in ids:
			elements.append(Doc.GetElement(id))
		all_elements.append(elements)
	
OUT = all_warns, all_elements

If I look at the “all_warns”, then I get Document and Warning.
If I look at the “all_elements”, then I get the Warnings and Elements.
I just cannot figure out how to get all three levels in one list. Can somebody please help me?

@mate Something like this?

docs = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
OUT = []
for doc in docs:
	#Append Filename to Document Set
	docSet = [doc.PathName.split('\\')[-1].split('.')[0]]
	warns = doc.GetWarnings()
	for warn in warns:
		#Append Warning to Warning Set
		warnSet = [warn.GetDescriptionText()]		 
		ids = warn.GetFailingElements()
		elems = []
		for id in ids:
			elems.append(doc.GetElement(id))
		#Append Element to Warning Set
		warnSet.append(elems)
		#Append Warning Set to Document Set
		docSet.append(warnSet)
	#Append Document Set to Output
	OUT.append(docSet)
2 Likes

@AmolShah Thank you very much. Based on your idea, I ended up with this:

docs = UnwrapElement(IN[0])

all_elems = []
for doc in docs:
    warns = doc.GetWarnings()
    docSet = []
    ids = []
    for warn in warns:
        ids = warn.GetFailingElements()
        elems = []
        for id in ids:
            elems.append(doc.GetElement(id))
        docSet.append(elems)
    all_elems.append(docSet)
OUT = all_elems

2021-09-11 13_19_50-Window
Please do have a nice day!

1 Like