<?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 Layer with Objects in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/6970780#M43200</link>
    <description>&lt;P&gt;This code is for VB.NET. you build the DLL and load it into AutoCAD by using 'NETLOAD'&amp;nbsp; command&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2017 13:34:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-03-24T13:34:06Z</dc:date>
    <item>
      <title>Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5166619#M43192</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found this code sample: &lt;A href="http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-DF8A64D3-AE09-4BCE-B9E1-1B642DA4FCFF" target="_self"&gt;http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-DF8A64D3-AE09-4BCE-B9E1-1B642DA4FCFF&lt;BR /&gt;&lt;/A&gt;However I just want to delete all of the objects on the layer, I dont care what they are I just want the whole layer and everything on it deleted.&lt;/P&gt;&lt;P&gt;Kinda like the LAYDEL express command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tony&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2014 12:53:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5166619#M43192</guid>
      <dc:creator>TTIII</dc:creator>
      <dc:date>2014-07-22T12:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5166993#M43193</link>
      <description>you can have a look in below link. hopefully it will serve your purpose&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff2566ffd511ff6f8c7ca-3cee.htm" target="_blank"&gt;http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff2566ffd511ff6f8c7ca-3cee.htm&lt;/A&gt;</description>
      <pubDate>Tue, 22 Jul 2014 14:51:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5166993#M43193</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-07-22T14:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167157#M43194</link>
      <description>&lt;P&gt;I'm tinkering with that, but I cant quite seem to remove the objects from the &lt;STRONG&gt;ObjectIdCollection.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Is that what I'm looking for?&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2014 15:31:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167157#M43194</guid>
      <dc:creator>TTIII</dc:creator>
      <dc:date>2014-07-22T15:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167501#M43195</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This snippet should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private string LayerDelete(Database db, string layerName)
        {
            if (layerName == "0")
                return "Layer '0' cannot be deleted.";
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var layerTable = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                if (!layerTable.Has(layerName))
                    return "Layer '" + layerName + "' not found.";
                try
                {
                    var layerId = layerTable[layerName];
                    if (db.Clayer == layerId)
                        return "Current layer cannot be deleted.";
                    var layer = (LayerTableRecord)tr.GetObject(layerId, OpenMode.ForWrite);
                    layer.IsLocked = false;
                    var blockTable = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    foreach (var btrId in blockTable)
                    {
                        var block = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                        foreach (var entId in block)
                        {
                            var ent = (Entity)tr.GetObject(entId, OpenMode.ForRead);
                            if (ent.Layer == layerName)
                            {
                                ent.UpgradeOpen();
                                ent.Erase();
                            }
                        }
                    }
                    layer.Erase();
                    tr.Commit();
                    return "Layer '" + layerName + "' have been deleted.";
                }
                catch (System.Exception e)
                {
                    return "Error: " + e.Message;
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2014 17:38:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167501#M43195</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-07-22T17:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167739#M43196</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is what I needed.&lt;/P&gt;&lt;P&gt;When I converted your code over to .NET you had used &lt;STRONG&gt;var&lt;/STRONG&gt; alot, I wasnt quite sure what to do, because the compiler was complaining though I fixed it. (I Think)&lt;/P&gt;&lt;P&gt;Here is my tweaked version. (&lt;STRONG&gt;Changes are in bold.&lt;/STRONG&gt;) Also I have &lt;STRONG&gt;Option Explicit On&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Tony&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DOT NET VERSION&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;Function LayerDelete(ByVal db As Database, ByVal layerName As String) As String
            If (layerName = "0") Then
                Return "Layer '0' cannot be deleted."
            End If
            Dim tr As Transaction = db.TransactionManager.StartTransaction
            Dim layerTable As &lt;STRONG&gt;LayerTable&lt;/STRONG&gt; = CType(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
            If Not layerTable.Has(layerName) Then
                Return ("Layer '" + (layerName + "' not found."))
            End If
            Try
                Dim layerId As &lt;STRONG&gt;Object&lt;/STRONG&gt; = layerTable(layerName)
                If Application.GetSystemVariable("Clayer") = layerName Then
                    Return "Current layer cannot be deleted."
                End If
                Dim layer As &lt;STRONG&gt;LayerTableRecord&lt;/STRONG&gt; = CType(tr.GetObject(layerId, OpenMode.ForWrite), LayerTableRecord)
                layer.IsLocked = False
                Dim blockTable As &lt;STRONG&gt;BlockTable&lt;/STRONG&gt; = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                For Each btrId As &lt;STRONG&gt;Object&lt;/STRONG&gt; In blockTable
                    Dim block As BlockTableRecord = CType(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord)
                    For Each entId As Object In block
                        Dim ent As Entity = CType(tr.GetObject(entId, OpenMode.ForRead), Entity)
                        If (ent.Layer = layerName) Then
                            ent.UpgradeOpen()
                            ent.Erase()
                        End If
                    Next
                Next
                layer.Erase()
                tr.Commit()
                &lt;STRONG&gt;MsgBox&lt;/STRONG&gt;("Layer '" + (layerName + "' have been deleted."))
            Catch e As System.Exception
                &lt;STRONG&gt;MsgBox&lt;/STRONG&gt;("Error: " + e.Message)
            End Try
        End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2014 19:02:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167739#M43196</guid>
      <dc:creator>TTIII</dc:creator>
      <dc:date>2014-07-22T19:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167949#M43197</link>
      <description>&lt;P&gt;Sorry for the 'var' (type inference) using.&lt;/P&gt;
&lt;P&gt;I don't know much about VB but I think the same can be done with option Infer = On (and option Strict = On to insure inference rather than late binding).&lt;/P&gt;
&lt;P&gt;To avoid late binding (and unboxing), you'd rather replace the following expressions:&lt;/P&gt;
&lt;PRE&gt;Dim layerId As &lt;STRONG&gt;Object&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;PRE&gt;For Each btrId As &lt;STRONG&gt;Object&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;PRE&gt;For Each entId As &lt;STRONG&gt;ObjectId&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;with strongly typed ones:&lt;/P&gt;
&lt;PRE&gt;Dim layerId As &lt;STRONG&gt;ObjectId&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;PRE&gt;For Each btrId As &lt;STRONG&gt;ObjectId&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;PRE&gt;For Each entId As &lt;STRONG&gt;ObjectId&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jul 2014 20:19:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5167949#M43197</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-07-22T20:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5169821#M43198</link>
      <description>&lt;P&gt;Thank you for clarifying this, it helped.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2014 14:58:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/5169821#M43198</guid>
      <dc:creator>TTIII</dc:creator>
      <dc:date>2014-07-23T14:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/6970666#M43199</link>
      <description>&lt;P&gt;How do you run this code?&lt;/P&gt;&lt;P&gt;It's not LSP, so what extension should I use?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 13:02:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/6970666#M43199</guid>
      <dc:creator>Haider_of_Sweden</dc:creator>
      <dc:date>2017-03-24T13:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Layer with Objects</title>
      <link>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/6970780#M43200</link>
      <description>&lt;P&gt;This code is for VB.NET. you build the DLL and load it into AutoCAD by using 'NETLOAD'&amp;nbsp; command&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 13:34:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/delete-layer-with-objects/m-p/6970780#M43200</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-03-24T13:34:06Z</dc:date>
    </item>
  </channel>
</rss>

