Not able to delete Extensible Storage schema
I'm trying to put together a command to erase Extensible Storage (ES) data and the corresponding Schemas for our addin in case if unwanted by the users or corrupt. I had no luck so far.
After the ES data has been written to the file it won't go away. I am being able to delete the DataStorage elements with no troubles, but the schemas keep popping up after erasing them.
The procedure I'm trying is:
- Open the Revit file with the saved ES data.
- Delete all the DataStorage elements holding the data.
- Save and close Revit, reopen the file again.
- Erase all schemas created by our addin.
- Save and close Revit to make sure I clear the schemas in memory.
- Start Revit again.
- Use the Schema.ListSchemas() function with no documents open to make sure our custom schemas are not loaded, this clears out.
- Open the file and use the Schema.ListSchemas() function, now all the schemas that I have erased previously reappear after opening the file!
I'm using the same procedure found in the "ExtensibleStorageUtility" code example in the Revit SDK in a macro (code below).
One observation I have that if I close Revit without saving after step 4 I get no warning to save the file as if no changes happened to the file, although I'm doing the erase inside a transaction.
This article has some info on ES and Schema behaviors that I tried to utilize but didn't work.
Below is the macro function I'm using:
public void DeleteSchemas() {
var uiDoc = this.ActiveUIDocument;
var document = uiDoc.Document;
var message = "";
IList<Schema> schemas = Schema.ListSchemas();
int deleted = 0;
int count = schemas.Count;
using(Transaction tErase = new Transaction(document, "Erase EStorage")){
tErase.Start();
foreach (Schema schema in schemas.Where(s=> s.VendorId == "MYAD"))
{
//Note-this will delete storage of this schema in *all* open documents.
try{
document.EraseSchemaAndAllEntities(schema);
Schema.EraseSchemaAndAllEntities(schema, true);
deleted++;
} catch {
}
}
tErase.Commit();
}
message =string.Format( "{0} storage elements out of {1} were deleted.", deleted.ToString(), count.ToString());
TaskDialog.Show("ExtensibleStorageUtility", message);
}
Any light on this would be much appreciated.
Thanks!