Attached Detail Groups methods - Python list hierarchy

I’m trying to get the new Attached Detail Group API methods into some custom Nodes. (with the extra goal of learning more Python applied in Dynamo)

Starting with the GetAvailableAttachedDetailGrouptTypeIds command (so I can use that result in the Show and Hide commans later), got me results.

First problem was that I got the Ids returned as strings not as actual Revit Element, but the list structure was good (My example file has 3 Model Group instances with 3 Attached Detail Group Types each, so I got a 3x3 list)

When I started looping over that list with GetElement to convert the Id strings into actual elements the hierarchy of my list changed and the output was a 1x9 list.

Can someone point out how I can maintain the original structure here?


I guess you are appending the elements into the same list. Try appending them into seprate sub-lists, then appending the sublist to the original list. Just added two lines here (and modified one), hope that works (I may have miswritten the others)

groups = UnwrapElement(IN[0])
detailGroups = []

doc = DocumentManager.Instance.CurrentDBDocument

for group in groups:
	sub_detailGroups = []
	detailgroup = group.GetAvailableAttachedDetailGroupTypeIds()
	for detail in detailgroup:
		output = doc.GetElement(detail)

OUT = detailGroups

The point is : the append() method only add items to the end of a list, it cannot maintain a structure in any way, so you have to recreate the structure by creating the sublists yourself : it is easily done by creating an additional sublist in each subloop.

1 Like

Thank you, that indeed did the trick. Also explained why playing around with the indent on the append action did not have the desired result.