<?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 Layer Swap Error in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418583#M72038</link>
    <description>Hi, all.&lt;BR /&gt;
Below is the way to get error.&lt;BR /&gt;
What do I have to check and fix it completely?&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
How to Get Error   &lt;BR /&gt;
1.Create "SourceLayer" layer-------&amp;gt; Layer1&lt;BR /&gt;
2.Create "TargetLayer" Layer-------&amp;gt; Layer2&lt;BR /&gt;
3.Erase "SourceLayer" Layer&lt;BR /&gt;
4.Create "SourceLayer" Layer&lt;BR /&gt;
5.Excute Below Code&lt;BR /&gt;
   Then we can get "eDuplicateRecordName"  error&lt;BR /&gt;
6.  Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)------&amp;gt; rewrite True to False&lt;BR /&gt;
    Then we can get "eWasErased" error&lt;BR /&gt;
&lt;BR /&gt;
Shared Sub SwapLayers(ByVal Layer1 As String, ByVal Layer2 As String)&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
            Using tr As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction&lt;BR /&gt;
                Using lt As LayerTable = tr.GetObject(db.LayerTableId, OpenMode.ForWrite, True, True)&lt;BR /&gt;
                    lt.UpgradeOpen()&lt;BR /&gt;
                    If lt.Has(Layer1) AndAlso lt.Has(Layer2) Then&lt;BR /&gt;
                        Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)&lt;BR /&gt;
                        Dim ltr2 As LayerTableRecord = tr.GetObject(lt.Item(Layer2), OpenMode.ForWrite, True, True)&lt;BR /&gt;
                        ltr.Name = "SwapLayers_temp"&lt;BR /&gt;
                        ltr2.Name = Layer1&lt;BR /&gt;
                        ltr.Name = Layer2&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                        Application.DocumentManager.MdiActiveDocument.Editor.Regen()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub</description>
    <pubDate>Tue, 27 Jan 2009 08:24:54 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-01-27T08:24:54Z</dc:date>
    <item>
      <title>Layer Swap Error</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418583#M72038</link>
      <description>Hi, all.&lt;BR /&gt;
Below is the way to get error.&lt;BR /&gt;
What do I have to check and fix it completely?&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
How to Get Error   &lt;BR /&gt;
1.Create "SourceLayer" layer-------&amp;gt; Layer1&lt;BR /&gt;
2.Create "TargetLayer" Layer-------&amp;gt; Layer2&lt;BR /&gt;
3.Erase "SourceLayer" Layer&lt;BR /&gt;
4.Create "SourceLayer" Layer&lt;BR /&gt;
5.Excute Below Code&lt;BR /&gt;
   Then we can get "eDuplicateRecordName"  error&lt;BR /&gt;
6.  Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)------&amp;gt; rewrite True to False&lt;BR /&gt;
    Then we can get "eWasErased" error&lt;BR /&gt;
&lt;BR /&gt;
Shared Sub SwapLayers(ByVal Layer1 As String, ByVal Layer2 As String)&lt;BR /&gt;
        Using db As Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
            Using tr As Transaction = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction&lt;BR /&gt;
                Using lt As LayerTable = tr.GetObject(db.LayerTableId, OpenMode.ForWrite, True, True)&lt;BR /&gt;
                    lt.UpgradeOpen()&lt;BR /&gt;
                    If lt.Has(Layer1) AndAlso lt.Has(Layer2) Then&lt;BR /&gt;
                        Dim ltr As LayerTableRecord = tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite, True, True)&lt;BR /&gt;
                        Dim ltr2 As LayerTableRecord = tr.GetObject(lt.Item(Layer2), OpenMode.ForWrite, True, True)&lt;BR /&gt;
                        ltr.Name = "SwapLayers_temp"&lt;BR /&gt;
                        ltr2.Name = Layer1&lt;BR /&gt;
                        ltr.Name = Layer2&lt;BR /&gt;
                        tr.Commit()&lt;BR /&gt;
                        Application.DocumentManager.MdiActiveDocument.Editor.Regen()&lt;BR /&gt;
                    End If&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub</description>
      <pubDate>Tue, 27 Jan 2009 08:24:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418583#M72038</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-01-27T08:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Layer Swap Error</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418584#M72039</link>
      <description>If you search the group on eWasErased you will find plenty of discussion on this topic. As you have found out the API stupidly returns erased items so you have to loop through the table to find the non erased item.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The attached function retrieves the ObjectId of the SymbolTableRecord. The function requires the ObjectId of the SymbolTable and the name of the SymbolTableRecord as as string.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The function finds the non-erased item when there are erased ones with the same name. It returns ObjectId.Null if the record does not exist.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards - Nathan</description>
      <pubDate>Tue, 27 Jan 2009 21:21:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418584#M72039</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-01-27T21:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Layer Swap Error</title>
      <link>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418585#M72040</link>
      <description>Thank you so much. &lt;BR /&gt;
It's working very well without an error.</description>
      <pubDate>Wed, 28 Jan 2009 05:10:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/layer-swap-error/m-p/2418585#M72040</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-01-28T05:10:42Z</dc:date>
    </item>
  </channel>
</rss>

