Ungroup after Attatched Detail Group Show

Hello everyone!
I´ve been having some issues getting dynamo to ungroup a group containning an Attatched Detail Group. This is the Group after running the graph without trying to ungroup it works just fine, plus if i ungroup it with dynamo or manually after the graph is done there is no problem.

However if i ungroup it within the same graph it appears to wait until graph is done to apply ShowAllAttachedDetailGroups to the view so it ungroups without the Attached Detail Group


Python Script

Hello
try to ungroup Attatched Detail Group first, then ungroup the Model Group

import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

toList = lambda x : x if hasattr(x, '__iter__') else [x]
lstOfgroup = toList(UnwrapElement(IN[0]))
	
activeView = doc.ActiveView
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
out = []
for gp in lstOfgroup:
	gp.ShowAllAttachedDetailGroups(activeView)
	doc.Regenerate()
	temp = []
	#ungrpoup Attached Detail Group
	filterG = System.Predicate[System.Object](lambda x : x.AttachedParentId == gp.Id)
	gpDetails = FilteredElementCollector(doc, activeView.Id).OfCategory(BuiltInCategory.OST_IOSAttachedDetailGroups).ToElements().FindAll(filterG)
	for gpDetail in gpDetails:
		ungroupDet_ids = gpDetail.UngroupMembers()
		temp.extend([doc.GetElement(xId) for xId in ungroupDet_ids])
	#ungrpoup Model Group
	ungroupids = gp.UngroupMembers()
	temp.extend([doc.GetElement(xId) for xId in ungroupids])
	out.append(temp)
TransactionManager.Instance.TransactionTaskDone()

OUT = out
1 Like

Thank You! this is perfect!

Hi
Thank for your code first.

I want to ask that can I ungroup a group and then do my dynamo script.
in the end, regroup the previous elements that what I ungrouped before ?

Brcause when I implement my dynamo, Revit will ask me for ungroup the group.
But I want to keep the group, also do my dynamo.

Hi Jack,
Yes! You can definitely do all those steps within the same script.

I would advise you to retrieve the members of the group right after selecting the group, then follow along with your script and at the end create a new group using the retrieved elements from the first selected group, instead of trying to regroup the elements in the same group as before.

If you want to delete the previous group you could add a “wait for” node after the group selection as a passthrough that waits for the last script node then deletes the group and then you can create a new group with the same name as the previous.

1 Like

Thank your immediate comment and advise.

I will test as soon as possible.