Hello,
I want to delete all assemblies of the project and also I do not want to have to hit the button Delete Element(s) of the warning error screen given by Revit immediately after an assembly is deleted.
I tried with python code like that but I still see the error window and it does not conclude until I select that option to Delete elements, it is like to confirm I acknowledge all of it will be removed.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# Retrieve assembly elements from the document
collector = FilteredElementCollector(doc)
assemblies = collector.OfCategory(BuiltInCategory.OST_Assemblies).WhereElementIsNotElementType().ToElements()
# Disassemble assemblies
TransactionManager.Instance.EnsureInTransaction(doc)
for assinst in assemblies:
assinst.Disassemble()
TransactionManager.Instance.TransactionTaskDone()
# Handle failures
TransactionManager.Instance.EnsureInTransaction(doc)
options = TransactionManager.Instance.GetFailureHandlingOptions()
options.SetFailuresPreprocessor(DeleteElementsPreprocessor())
TransactionManager.Instance.SetFailureHandlingOptions(options)
TransactionManager.Instance.TransactionTaskDone()
class DeleteElementsPreprocessor(IFailuresPreprocessor):
def PreprocessFailures(self, failuresAccessor):
failureMessages = failuresAccessor.GetFailureMessages()
for failureMessage in failureMessages:
if failureMessage.GetFailureDefinitionId() == BuiltInFailures.GeneralFailures.DeletingElementsFailures:
failuresAccessor.ResolveFailure(failureMessage)
return FailureProcessingResult.Continue
OUT = "Assemblies disassembled successfully."