<?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: Revit freezes using Element.Delete() on a Revit Link Type? (Code included) in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5662368#M72110</link>
    <description>&lt;P&gt;Dear Jack,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reporting this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds as if you are hitting some internal element that should not be removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Maybe you can add some additional filter checks to avoid hitting the sensitive element that is causing this behaviour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, since you are checking the CanBeDeleted predicate before attempting to delete, this sounds like an error to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide a full reproducible case, i.e. the entire Visual Studio solution, add-in manifest, and minimal sample model to run this in?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I'll raise an issue with the development team to explore in more depth for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&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>Wed, 03 Jun 2015 09:08:21 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2015-06-03T09:08:21Z</dc:date>
    <item>
      <title>Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5662345#M72109</link>
      <description>&lt;P&gt;Hi, I am trying to remove all revit links from a revit file and for some reason when i call delete on the revit link type revit freezes and asks me if i would like to create a recovery file. my experience with revit is not huge so apologies if this is a stupid question.&lt;BR /&gt;&lt;BR /&gt;Here is my code(Ignore commented code)&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://forums.autodesk.com/t5/image/serverpage/image-id/171637i723B96140FE41AEF/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Revit freeze code.PNG" title="Revit freeze code.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance, you guys are always great.&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2015 09:04:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5662345#M72109</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-03T09:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5662368#M72110</link>
      <description>&lt;P&gt;Dear Jack,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reporting this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds as if you are hitting some internal element that should not be removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;SPAN style="line-height: 15px;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Maybe you can add some additional filter checks to avoid hitting the sensitive element that is causing this behaviour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, since you are checking the CanBeDeleted predicate before attempting to delete, this sounds like an error to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please provide a full reproducible case, i.e. the entire Visual Studio solution, add-in manifest, and minimal sample model to run this in?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I'll raise an issue with the development team to explore in more depth for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&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>Wed, 03 Jun 2015 09:08:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5662368#M72110</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2015-06-03T09:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5663996#M72111</link>
      <description>&lt;P&gt;Thank you Jeremy, here is everything you requested, If there is any problems let me know.&amp;nbsp;&lt;BR /&gt;Thanks again,&lt;BR /&gt;Jack&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 09:04:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5663996#M72111</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-04T09:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664097#M72112</link>
      <description>&lt;P&gt;Dear Jack,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your sample material.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created a cleaned up version of your sample add-in, attached it below in PurgeLinksFreeze.zip, and can reproduce the behaviour you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll pass it on to the development team as soon as I can. I don't have access to the system right now due to travels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll let you know as soon as I have any news.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 11:07:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664097#M72112</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2015-06-04T11:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664126#M72113</link>
      <description>&lt;P&gt;Sorry, Jack, it seems it was your own fault after all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You must not modify elements that you are iterating over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That corrupts the iteration process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the new attached solution that achieves the deletion with no freeze:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  UIApplication uiapp = commandData.Application;
  UIDocument uidoc = uiapp.ActiveUIDocument;
  Document doc = uidoc.Document;

  FilteredElementCollector links 
    = new FilteredElementCollector( doc )
      .OfClass( typeof( RevitLinkType ) );

  ICollection&amp;lt;ElementId&amp;gt; ids = links.ToElementIds();

  using( Transaction t = new Transaction( doc ) )
  {
    t.Start( "Delete Links" );
    doc.Delete( ids );
    t.Commit();
  }

  return Result.Succeeded;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attached the complete solution, source code and add-in manifest below.&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 11:30:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664126#M72113</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2015-06-04T11:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Revit freezes using Element.Delete() on a Revit Link Type? (Code included)</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664441#M72114</link>
      <description>&lt;P&gt;Thanks a million jeremy, You have been very helpful, I am still learning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jack&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 14:11:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-freezes-using-element-delete-on-a-revit-link-type-code/m-p/5664441#M72114</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-06-04T14:11:42Z</dc:date>
    </item>
  </channel>
</rss>

