Here we go…
I have a user with a rogue library of detail items that are filled with unused nested families, that are themselves nested in some cases. I am putting together a script that will compare used families and types versus those that are not. This piece works great to delete elements of a specific category. But now I would like to run it on a model against the 300+ detail item families to “purge” the nested stuff out. Oh, and this is the same case for several current models so really doing this manually is just out.
Here is the current graph:
Elements - Purge Detail Items (beta).dyn (21.7 KB)
Before:
After:
Where I am having trouble is doing this work on a family while in the project environment. I have got the nodes getting the families and getting all of the elements of the category from the family, but can’t get the elements to delete from the Family and then load back in.
Here is code from “Delete Elements in Family”
#Based on DanEDU
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
# Revit and Dynamo modules
from Autodesk.Revit.DB import FamilyManager, BuiltInParameterGroup, ParameterType
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
docs = IN[0]
elems = IN[1]
if docs == 'Current.Document':
docs = DocumentManager.Instance.CurrentDBDocument
# make a list
if not isinstance(docs, list):
docs = [docs]
if not isinstance(elems, list):
elems = [elems]
log = []
#Do the work
if docs > 0:
for doc in docs:
TransactionManager.Instance.EnsureInTransaction(doc)
for elem in elems:
try:
log.append('ok')
doc.FamilyManager.Delete(elem.Id)
except:
log.append('No')
TransactionManager.Instance.ForceCloseTransaction()
OUT = docs, elems, log
Here is the code for “All Elements of Category in Doc”
#based on node by Julien Benoit @jbenoit44
import System
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
cats = IN[1]
if not isinstance(cats, list): cats = [cats]
docs = IN[0]
if not isinstance(docs, list): docs = [docs]
elemlist = []
for doc in docs:
try:
for item in cats:
collector = FilteredElementCollector(doc)
collector.OfClass(FamilySymbol)
bic = System.Enum.ToObject(BuiltInCategory, item.Id)
elemlist.append(collector.OfCategory(bic).ToElements())
except:
log = 'Error'
#TransactionManager.Instance.ForceCloseTransaction()
OUT = elemlist
This node also usually make the graph “run” indefinitely so I have to restart.
I get the Elements from the Families, and the Family Documents just fine, but need to access them to delete and then load.
Any thoughts would be greatly appreciated!