Ungroup elements in document

Hi,

I’m working on a script to prepare models for issue in the background.

One stage where im having trouble is ungrouping elements. the clockwork node ‘group.ungroup’ is returning ‘empty list’ rather than a list of ungrouped elements. ‘empty list’ is typcially returned when a non-group element is passed through this node.

This is odd, because im sure the ungroup node was working for documents before. This may, however, have just been my optimistic memory.

has anyone tried ungrouping elements in a background opened document?

Ungrouping is an action that requires a transaction in the Revit API (which, in turn, needs a document reference). The Ungroup node uses the current document for that. For it to work on other documents in the background, you would have to pass the respective model‘s doc reference. I am writing this from my phone so I can‘t be more exact than this but you could look at some of Clockwork‘s selection nodes (that have optional doc inputs) on how to modify the node to better suit your needs.

Thanks Andreas,

Supprisingly painless to mash your super collector node with ungroup, even with next to no python knowlege.

for the record, code is below.

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

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

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

DocToUse = IN[1]
doc = DocToUse
groups = UnwrapElement(IN[0])
elementlist = list()
TransactionManager.Instance.EnsureInTransaction(doc)
for group in groups:
	try:
		ids = group.UngroupMembers()
		ungrouped = list()
		for id in ids:
			ungrouped.append(group.Document.GetElement(id))
		elementlist.append(ungrouped)
	except:
		elementlist.append(list())
TransactionManager.Instance.TransactionTaskDone()

OUT = elementlist
1 Like

oddly, this has now stopped working the first time I press run. If I rewire the graph slightly, pressing run the second time works. is this some kind of problem with the file being open?

Run 1

Run 2

1 isloated test 2.dyn (52.2 KB)