Hi All,
Something that we come across quite frequently when issuing a model to other consultants. I have written a code to delete all views, schedules, sheets, links (both cad and revit) as well as unplaced rooms. However, having a bit of issue trying to keep the splash screen when deleting all views. Any help is appreciated. Many thanks.
title = “Model CleanUp For Export”
author = “Ahmed Helmy”
import clr
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitNodes”)
import Revit
doc = revit.ActiveUIDocument.Document
t = Transaction(doc, “Model Export”)
Transaction Start
try:
t.Start()
Filtered Element Collectors
Filter CAD Links
cad_links = FilteredElementCollector(doc).OfClass(clr.GetClrType(ImportInstance)).ToElementIds() for cad in cad_links: doc.Delete(cad)
Filter Revit Links
rvt_links = FilteredElementCollector(doc).OfClass(clr.GetClrType(RevitLinkInstance)).ToElementIds() for rvt in rvt_links: doc.Delete(rvt)
Filtering Sheets
all_sheets = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Sheets).WhereElementIsNotElementType().ToElementIds() for sheet in all_sheets: doc.Delete(sheet)
Filtering Schedules
all_schedules = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Schedules).WhereElementIsNotElementType().ToElementIds() for schedule in all_schedules: doc.Delete(schedule)
Filtering Views
all_views = FilteredElementCollector(doc).OfClass(clr.GetClrType(View)).ToElementIds() for view in all_views: try: doc.Delete(view) except: pass t.Commit()
except:
t.RollBack
Filtering Rooms
all_rooms = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms)
t.Start()
placed , unplaced = ,
for room in all_rooms:
if room.Area > 0: placed.append(room) else: unplaced.append(room.Id)
#Delete unplaced rooms
delrooms = [doc.Delete(i) for i in unplaced]
t.Commit()