I’m trying to delete a list of grouped elements (any wall hosted families) so I can get the solids from walls excluding any openings. The problem I have is that the deleted elements stay deleted from the groups in Revit after the transaction.
Perhaps I’m trying to get too much out of a sub-transaction but I thought the quickest way about this would be to start the sub-transaction, delete grouped elements, extract solids from remaining elements and append to a list, rollback sub to undo any deletions. That’s the logic anyway but it doesn’t work… My attempt is below and any advice would be much appreciated. Thanks!
The inputs are; 1. Elements to obtain solid geometry from, 2. Elements to be deleted and 3. the affected Groups.
The outputs are; 1. Extracted solids, 2. Problematic elements without solids, 3. Groups containing problematic elements, 4. Element Ids of Problematic Elements
import clr clr.AddReference("RevitAPI"); clr.AddReference("RevitNodes") import Autodesk, Revit; clr.ImportExtensions(Revit.Elements); clr.ImportExtensions(Revit.GeometryConversion); from Autodesk.Revit.DB import * clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument elements = UnwrapElement(IN) #sublists per model group deleteList = UnwrapElement(IN) #elements to be deleted groupsIn = UnwrapElement(IN) #model groups containing all elements outlist =  warnings =  groups =  groupIDs =  ids =  options = Options() TransactionManager.Instance.EnsureInTransaction(doc) trans = SubTransaction(doc) trans.Start() for d in deleteList: doc.Delete(d.Id) doc.Regenerate() for en, el in enumerate(elements): elList =  for e in el: geo = e.get_Geometry(options) for obj in geo: if isinstance(obj,Solid): try: geom = obj.ToProtoType() if str(geom) == 'Solid': elList.append(geom) else: ids.append(e.Id) groups.append(groupsIn[en]) except: ids.append(e.Id) groups.append(groupsIn[en]) else: ids.append(e.Id) groups.append(groupsIn[en]) outlist.append(elList) trans.RollBack() TransactionManager.Instance.TransactionTaskDone() warnings = [doc.GetElement(x) for x in ids] OUT = outlist, warnings, groups, ids