I have about 5 Schema in a RVT model we have that were left behind from consultants. Now that those consultants are out, I’m trying to figure out how to remove those Schemas. I’m looking to list them so we can see waht ones there are. Then delete them out. Ive been spending a bit of time looking for this, and there doesnt seem to be a solution.
You can use the ListSchemas()
method to return all schemas in extensible storage. Then you’ll have to get some sort of identity data (Name and/or Documentation) to determine what they are.
ListSchemas Method (revitapidocs.com)
Note that ‘List Schemas’ will return all schemas in memory, and that schemas are added to memory as files utilizing the schema are opened. Once in memory the only way to truest remove them is to close the Revir session.
This topic already covers this.
Here an example
import clr
import sys
import System
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB.ExtensibleStorage import Schema
lstSchemas_to_del = [s for s in Schema.ListSchemas() if s.SchemaName in IN[0]]
TransactionManager.Instance.EnsureInTransaction(doc)
for schema in lstSchemas_to_del:
if sdkNumber < 2021:
Schema.EraseSchemaAndAllEntities(schema, True)
else:
doc.EraseSchemaAndAllEntities(schema)
TransactionManager.Instance.TransactionTaskDone()
Note
look like a GPT answer
Schema.Lookup() need a Guid as parameter not the schema name
You have a tool specifically for that in pyRevit.
The code looks like this
"""Erase selected data schema and its entities."""
from pyrevit import revit, DB
from pyrevit import forms, HOST_APP
doc = revit.doc
class DataSchemaItem(forms.TemplateListItem):
@property
def name(self):
return '{} ({})'.format(self.item.SchemaName, self.item.GUID)
schemas = DB.ExtensibleStorage.Schema.ListSchemas()
sschemas = \
forms.SelectFromList.show([DataSchemaItem(x) for x in schemas],
multiselect=True) or []
for sschema in sschemas:
with revit.Transaction("Remove Schema"):
try:
if HOST_APP.version <= 2020:
DB.ExtensibleStorage.Schema.EraseSchemaAndAllEntities(
schema=sschema,
overrideWriteAccessWithUserPermission=True
)
else:
doc.EraseSchemaAndAllEntities(sschema)
except Exception as e:
print(e)
This was great. thank you.
For Revit 2023, I managed to find and “delete” the schema (IronPython reports that the schema was erased), but at the same time, Revit Lookup still shows it in the list. I tried purging after deletion (it appears in the purge list after the “deletion”), but when I close and reopen the model, it’s still there.
It’s a schema from an add-in we tested, and it’s bound to Project Information (which appears in the list of elements).
Any idea how to actually delete this one?