Not able to delete Extensible Storage schema

Not able to delete Extensible Storage schema

snajjar
Contributor Contributor
13,974 Views
85 Replies
Message 1 of 86

Not able to delete Extensible Storage schema

snajjar
Contributor
Contributor

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:

  1. Open the Revit file with the saved ES data.
  2. Delete all the DataStorage elements holding the data.
  3. Save and close Revit, reopen the file again.
  4. Erase all schemas created by our addin.
  5. Save and close Revit to make sure I clear the schemas in memory.
  6. Start Revit again.
  7. Use the Schema.ListSchemas() function with no documents open to make sure our custom schemas are not loaded, this clears out.
  8. 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!

13,975 Views
85 Replies
Replies (85)
Message 81 of 86

jeremy_tammik
Alumni
Alumni

What version are you working with? Did you test the extensible storage enhancement added in Revit  2024.1.1?

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 82 of 86

hemmesMW2F3
Contributor
Contributor

@jeremy_tammik As is so often the case, you pointed me in the right direction.
I was indeed working with models upgraded to 2024, and upgrading to Revit 2024.2.2 solved my issues.
Glad the dev team sorted it out!

0 Likes
Message 83 of 86

jeremy_tammik
Alumni
Alumni

That is a great relief to hear. Thank you for the confirmation and appreciation. Very glad to hear it worked out.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 84 of 86

c_hanschen
Advocate
Advocate
Thanks for your code!

My Revit 2024 has been updated to version 24.2, but I get:
'EraseSchemaAndAllEntities' is not an member of 'Schema'.
Line: Schema.EraseSchemaAndAllEntities(schema, true)

Schema is 'Autodesk.Revit.DB.ExtensibleStorage.Schema', so that's checked, but I am missing a member!

any advice?

Thanks in advance!

Chris Hanschen
LKSVDD architecten
The Netherlands!
0 Likes
Message 85 of 86

jeremy_tammik
Alumni
Alumni

revitapidocs.png

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 86 of 86

JeffStuy
Contributor
Contributor
Although it has been a while, I restarted my investigation into Extensible storage, DataStorage, Schema, etc.
For anyone interested.  It is possible to remove schema in a 2023 model.  At this point, no one may care but just in case.
 
I used "Revit Explorer" to verify.
 
Procedures:
For Revit 2023.1.6
0. Start Revit, open model (without DS or schema)
1. Add schema and data storage
* all show as existing
2. Close Revit, re-start Revit & model
* all show as existing
3. Erase DataStorage
* DS gone, Schema Exist
4. Erase Schema
* all schema show as existing
5. Purge schema
6. Save file
* all schema show as existing
7. Purge schema
8. Save file
* all schema show as existing
9. Quit Revit, re-start Revit & model
* all schema show as removed
 
Important here is that you must purge, save, purge again, save, quit.
Without the 2nd purge and the save between, the schema remains.
 
For Revit 2024.3.3 & 2026
0. Start Revit, open model (without DS or schema)
1. Add schema and data storage
* all show as existing
2. Close Revit, re-start Revit & open model
* all show as existing
3. Erase DataStorage
4. Erase Schema
* DS gone, all schema show as existing
5. Save file
* all schema show as existing
6. Quit Revit, re-start Revit & open model
* all schema show as removed
 
Important here is that the schema disappears only after quitting Revit.
 
Although this is not how I would like to be able to use Extensible storage, it makes some sense. 
Per the API documentation:
"Schemas are stored in the memory of the running instance of Revit"
 
The this reason, schema, although saved with a document, is a Revit application object.  
 
The nice thing is, if you close the file to which DS & Schema added, then create a new file, the schema in memory is NOT be added to this new file.
 
Lastly, I checked out the suggestion about modifying the field value stored within the entity.  
As you suggested, I was able to modify the value which may make using Extensible Storage possible.

 

0 Likes