<?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: Delete Materials is not working in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/delete-materials-is-not-working/m-p/6214635#M66941</link>
    <description>&lt;P&gt;You cannot modify the iteration variables within the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always terminate the filtered element collector iteration before starting to modify anything at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Collect all the materials to delete and store their element ids.&lt;/P&gt;
&lt;P&gt;2. Open the transaction.&lt;/P&gt;
&lt;P&gt;3. Delete the elements with&amp;nbsp;one single call to the&amp;nbsp;Document.Delete method taking an ICollection of ElementIds argument.&lt;/P&gt;
&lt;P&gt;4. Commit the transaction.&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, 14 Mar 2016 15:59:06 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2016-03-14T15:59:06Z</dc:date>
    <item>
      <title>Delete Materials is not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/delete-materials-is-not-working/m-p/6213755#M66940</link>
      <description>&lt;P&gt;Hello, everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with problem. Delete element by Id is not working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    Private Sub DataTransferStartButton_Click(sender As Object, e As EventArgs) Handles DataTransferStartButton.Click

        Dim App As Autodesk.Revit.UI.UIApplication = myCD.Application()
        Dim UIDoc As UIDocument = App.ActiveUIDocument
        Dim Doc As Document = App.ActiveUIDocument.Document

        App.OpenAndActivateDocument("C:\Users\Pashin.Evgeniy\Desktop\001_Проба.rfa")

        Dim tr As New Transaction(Doc, "DeleteAllElements")
        tr.Start()

        Try
            Dim coll As FilteredElementCollector = New FilteredElementCollector(Doc).OfClass(GetType(Material))
            For Each dtFillPaternElement As Autodesk.Revit.DB.Material In coll
                Doc.Delete(dtFillPaternElement.Id)
                MsgBox("I kill material with name " &amp;amp; dtFillPaternElement.Name.ToString)
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        tr.Commit()
        tr.Dispose()

    End Sub&lt;/PRE&gt;&lt;P&gt;I'm using ExternalCommand and myForm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;myForm.ShowDialog( ) is not working!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using myForm.Show( ) - and It's better...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Family project is opening but materials is not deleted!!! Why? Transaction is not completed!!! Why?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 08:36:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/delete-materials-is-not-working/m-p/6213755#M66940</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-03-14T08:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Materials is not working</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/delete-materials-is-not-working/m-p/6214635#M66941</link>
      <description>&lt;P&gt;You cannot modify the iteration variables within the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Always terminate the filtered element collector iteration before starting to modify anything at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Collect all the materials to delete and store their element ids.&lt;/P&gt;
&lt;P&gt;2. Open the transaction.&lt;/P&gt;
&lt;P&gt;3. Delete the elements with&amp;nbsp;one single call to the&amp;nbsp;Document.Delete method taking an ICollection of ElementIds argument.&lt;/P&gt;
&lt;P&gt;4. Commit the transaction.&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, 14 Mar 2016 15:59:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/delete-materials-is-not-working/m-p/6214635#M66941</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2016-03-14T15:59:06Z</dc:date>
    </item>
  </channel>
</rss>

