<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: InternalException when using Schema.EraseSchemaAndAllEntities() in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4614735#M78387</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I finally found that the&amp;nbsp;InternalException was caused by having projects linked in the document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to Unload all linked files first and run the&amp;nbsp;method&amp;nbsp;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;Schema.EraseSchemaAndAllEntities&lt;/SPAN&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;(schema, false) and then Load the files again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;This is the final custom method that worked for me including the transaction.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void DeleteSchema()
{
    using (Transaction trans = new Transaction(_doc, "Delete Schema Transaction"))
    {
        trans.Start();
        Schema schema = Schema.Lookup(_schemaGuid);
        Schema.EraseSchemaAndAllEntities(schema, false); 
        trans.Commit();
    }                       
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marc&lt;/P&gt;</description>
    <pubDate>Tue, 12 Nov 2013 20:07:43 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2013-11-12T20:07:43Z</dc:date>
    <item>
      <title>InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4598127#M78381</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an&amp;nbsp;InternalException when I run this method. I have tried it with the argument overrideWriteAccessWithUserPermission&amp;nbsp;&lt;SPAN style="font-size: 11px; white-space: pre-wrap;"&gt;set to false and it also trows an &lt;SPAN&gt;InternalException.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void DeleteAllSchemas()
{
      using (Transaction trans = 
                  new Transaction(_doc, "Delete Schemas Transaction"))
      {
          trans.Start();
          IList&amp;lt;Schema&amp;gt; schemas = Schema.ListSchemas();

          foreach (Schema schema in schemas)
          {
               Schema.EraseSchemaAndAllEntities(schema, true);  
          }

          trans.Commit();
      }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; Any idea on how to adress this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marc&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2013 22:34:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4598127#M78381</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-06T22:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4599367#M78382</link>
      <description>&lt;P&gt;did a quick test and works OK, my test model have schemas but not yet attach ES to any element, is it because you still have ES attached to some elements? or it simply doesn't matter?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2013 08:54:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4599367#M78382</guid>
      <dc:creator>Ning_Zhou</dc:creator>
      <dc:date>2013-11-07T08:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4612527#M78383</link>
      <description>&lt;P&gt;Dear Marc,&lt;BR /&gt;&lt;BR /&gt;Thank you for your query.&lt;BR /&gt;&lt;BR /&gt;Basically, the Revit SDK ExtensibleStorageUtility shows you how to use this method.&lt;BR /&gt;&lt;BR /&gt;Ning, I believe it should work perfectly well even if entities using the schema still exist.&lt;BR /&gt;&lt;BR /&gt;One thing that strikes me as rather strange is that the Schema.EraseSchemaAndAllEntities method will delete storage of this schema in *all* open documents.&lt;BR /&gt;&lt;BR /&gt;In your code, you only have a transaction open on the document stored in the _doc variable.&lt;BR /&gt;&lt;BR /&gt;I wonder how this will affect other documents if you have no trnasaction open for them.&lt;BR /&gt;&lt;BR /&gt;I would suggest running this with only one document open in the current Revit session.&lt;BR /&gt;&lt;BR /&gt;Can you please confirm that this is in fact the case, please?&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Here is a list of The Building Coder topics related to this topic:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The last one, especially, may be of use.&lt;BR /&gt;&lt;BR /&gt;I hope this helps.&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 09:01:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4612527#M78383</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2013-11-12T09:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613533#M78384</link>
      <description>&lt;P&gt;Hi Jeremy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My document have one linked project in it, but it tried to run the code in a document with no links and I keep getting the same error. This is the code that I've been using for testing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void CreateESDSchema()
{
    using (Transaction trans = new Transaction(_doc, "Create Schema"))
    {
        trans.Start();

        Schema schema = Schema.Lookup(_schemaGuid);

        if (schema == null)
        {
            SchemaBuilder schemaBuilder = new SchemaBuilder(_schemaGuid);

            schemaBuilder.SetSchemaName("Tracking Elements");
            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

            FieldBuilder fieldBuilder = schemaBuilder
                .AddSimpleField("LinkedInstanceElementID", typeof(int));
            fieldBuilder.SetDocumentation("Instance Element Unique ID");

            fieldBuilder = schemaBuilder
                .AddSimpleField("LinkedTypeElementID", typeof(int));
            fieldBuilder.SetDocumentation("Type Element Unique ID");

            fieldBuilder = schemaBuilder
                .AddArrayField("InstanceParameters", typeof(string));
            fieldBuilder.SetDocumentation("List of instance parameters");

            fieldBuilder = schemaBuilder
                .AddArrayField("TypeParameters", typeof(string));
            fieldBuilder.SetDocumentation("List of type parameters");

            fieldBuilder = schemaBuilder
                .AddSimpleField("LinkedDocument", typeof(string));
            fieldBuilder.SetDocumentation("Document where element is linked");

            schema = schemaBuilder.Finish(); // register the Schema object
        }

        trans.Commit();
    }

}


public void SetDataLinkedInsElemID(int id)
{
    using (Transaction trans = new Transaction(_doc, "Store Data trans"))
    {
        trans.Start();
        Schema schema = Schema.Lookup(_schemaGuid);        

        Entity entity = new Entity(schema);
        entity.Set&amp;lt;int&amp;gt;(schema.GetField("ESD_LinkedInstanceElementID"), id);

        _modelElementInstance.SetEntity(entity); 

        trans.Commit();
    }
}


public void DeleteSchema()
{
       Schema schema = Schema.Lookup(_schemaGuid);
       Schema.EraseSchemaAndAllEntities(schema, true);            
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The variable&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;_modelElementInstance it's an element that I manually pick.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I run this w&lt;SPAN&gt;hen deleting the Schema I get the InternalException.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;CreateESDSchema();
SetDataLinkedInsElemID(123456);
DeleteSchema();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In one of your articles (&lt;A href="http://thebuildingcoder.typepad.com/blog/2013/08/deleting-and-updating-extensible-storage-schema.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2013/08/deleting-and-updating-extensible-storage-schema.html&lt;/A&gt;)&amp;nbsp;someone have a similar issue. Can you confirm if the issue is caused because the linked files?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding my code for testing, am I doing something wrong?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I highgly apreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 15:00:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613533#M78384</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T15:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613837#M78385</link>
      <description>&lt;P&gt;Dear Marc,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Revit handles element ids in extensible storage intelligently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to populate them all, at least with an InvalidElementId.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let us know whether this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 16:43:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613837#M78385</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2013-11-12T16:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613899#M78386</link>
      <description>&lt;P&gt;HI Jeremy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The type of fields used are just an example and I don't think is causing the error. The problem is that I can't delete the schema from the document if I want to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I knew that Revit handles elements ids intelligently&amp;nbsp;but just with elements within that document.&lt;/P&gt;&lt;P&gt;This addin is intended to track elements from linked projects, so I couldn't use this feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, let me know if you find any other issue that maybe causing that problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 17:01:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4613899#M78386</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T17:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4614735#M78387</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I finally found that the&amp;nbsp;InternalException was caused by having projects linked in the document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to Unload all linked files first and run the&amp;nbsp;method&amp;nbsp;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;Schema.EraseSchemaAndAllEntities&lt;/SPAN&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;(schema, false) and then Load the files again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f7f7f7; color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; white-space: pre-wrap; line-height: 14px;"&gt;This is the final custom method that worked for me including the transaction.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void DeleteSchema()
{
    using (Transaction trans = new Transaction(_doc, "Delete Schema Transaction"))
    {
        trans.Start();
        Schema schema = Schema.Lookup(_schemaGuid);
        Schema.EraseSchemaAndAllEntities(schema, false); 
        trans.Commit();
    }                       
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Marc&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2013 20:07:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4614735#M78387</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-11-12T20:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4649463#M78388</link>
      <description>&lt;P&gt;Dear Marc,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the confirmation!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To ensure that your work does not go unnoticed, here is a blog post reiterating the result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2013/11/erasing-extensible-storage-with-linked-files.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2013/11/erasing-extensible-storage-with-linked-files.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2013 14:39:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4649463#M78388</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2013-11-25T14:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: InternalException when using Schema.EraseSchemaAndAllEntities()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4675149#M78389</link>
      <description>&lt;P&gt;just noticed that even if all links are unloaded, but if i zoom to that element before using Schema.EraseSchemaAndAllEntities() then same exception occurred again:&lt;/P&gt;&lt;P&gt;ElementId id = ent.Get&amp;lt;ElementId&amp;gt;("MyField");&lt;BR /&gt;if (id != ElementId.InvalidElementId) uidoc.ShowElements(id);&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2013 10:04:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/internalexception-when-using-schema-eraseschemaandallentities/m-p/4675149#M78389</guid>
      <dc:creator>Ning_Zhou</dc:creator>
      <dc:date>2013-12-05T10:04:30Z</dc:date>
    </item>
  </channel>
</rss>

