<?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: Best pratices to create and edit layer in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11497301#M11207</link>
    <description>&lt;P&gt;I am not sure what your were thinking of "best practice" with this code, where you have already known LayerTable.Has() method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;LayerTable lytb = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                    foreach (ObjectId LyId in lytb)
                    {
                        LayerTableRecord ltbr = trans.GetObject(LyId, OpenMode.ForRead) as LayerTableRecord;

                        if (ltbr.Name == "Teste")
                        {
                            ltbr.UpgradeOpen(); 

                            ltbr.Color = Color.FromColorIndex(ColorMethod.ByLayer, 3);

                            LinetypeTable lttb = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                            if (lttb.Has("Hidden"))
                            {
                                ltbr.LinetypeObjectId = lttb["Hidden"];
                            }

                            trans.Commit();
                            doc.Editor.WriteMessage("\nLayer alterado");
                            break;

                        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you already know a block name ("Teste"), you simply do:&lt;/P&gt;
&lt;P&gt;var layerTable=(LayerTable)tran.GetObject(db.LayerTableId, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;LayerTableRecord layer;&lt;/P&gt;
&lt;P&gt;if (!layerTable.Has("Teste")&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layerTable.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer=new LayerTableRecord();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer.Name="Teste";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layerTable.Add(layer);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; tran.AddNewlyCreatedDBObject(....);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer=(LayerTableRecord)tran.GetObject(layerTable["Teste", OpenMode.ForWrite);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Change/Set layer's properties here&lt;/P&gt;
&lt;P&gt;layer.Color=...;&lt;/P&gt;
&lt;P&gt;layer.LineType=....;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the method Has(), there is no need to loop through LayerTable for each LayerTableRecord and test its name in order to find the layer in interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Oct 2022 19:23:27 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2022-10-20T19:23:27Z</dc:date>
    <item>
      <title>Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11495998#M11204</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I face two options here to create/edit layers in AutoCAD using C#. Which one is the better thinking about the good practices:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Access my LayerTable direct for write, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;LayerTable lytab = trans.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;

....Create or update my layer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or access my LaterTable for read, and use the instruction lytab.UpgradeOpen(), like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;LayerTable lytab = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

lytab.UpgradeOpen();

....Create or update my layer&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know that result of both is equals, but one is better of other? (thinking about erros, performance and etc...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 12:33:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11495998#M11204</guid>
      <dc:creator>seabrahenrique</dc:creator>
      <dc:date>2022-10-20T12:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11496031#M11205</link>
      <description>&lt;P&gt;And a complementar question:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I really need this foreach simply to find a layer in my LayerTable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;                    LayerTable lytb = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                    foreach (ObjectId LyId in lytb)
                    {
                        LayerTableRecord ltbr = trans.GetObject(LyId, OpenMode.ForRead) as LayerTableRecord;

                        if (ltbr.Name == "Teste")
                        {
                            ltbr.UpgradeOpen(); 

                            ltbr.Color = Color.FromColorIndex(ColorMethod.ByLayer, 3);

                            LinetypeTable lttb = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                            if (lttb.Has("Hidden"))
                            {
                                ltbr.LinetypeObjectId = lttb["Hidden"];
                            }

                            trans.Commit();
                            doc.Editor.WriteMessage("\nLayer alterado");
                            break;

                        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or is there another simple way to set a layer in my LayerTableRecord if i know that name?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, in VBA i can do:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim MyLayer as AcadLayer
MyLayer = ThisDrawing.Layer("NameOfLayer")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can i do something similar in C# .NET to set a layer in a LayerTableRecord ltr, if i already know the name of layer is "NameOfLayer", for example?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 12:29:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11496031#M11205</guid>
      <dc:creator>seabrahenrique</dc:creator>
      <dc:date>2022-10-20T12:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11496325#M11206</link>
      <description>&lt;P&gt;The get the layer objectId by name use the following:&lt;/P&gt;&lt;P&gt;(Sorry its in vb.net)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim lyrTbl As LayerTable = tr.GetObject(curDb.LayerTableId, OpenMode.ForRead)
Dim lyrId As ObjectId = lyrTbl.Item("MyLayer")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 13:59:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11496325#M11206</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2022-10-20T13:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11497301#M11207</link>
      <description>&lt;P&gt;I am not sure what your were thinking of "best practice" with this code, where you have already known LayerTable.Has() method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;LayerTable lytb = trans.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                    foreach (ObjectId LyId in lytb)
                    {
                        LayerTableRecord ltbr = trans.GetObject(LyId, OpenMode.ForRead) as LayerTableRecord;

                        if (ltbr.Name == "Teste")
                        {
                            ltbr.UpgradeOpen(); 

                            ltbr.Color = Color.FromColorIndex(ColorMethod.ByLayer, 3);

                            LinetypeTable lttb = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead) as LinetypeTable;
                            if (lttb.Has("Hidden"))
                            {
                                ltbr.LinetypeObjectId = lttb["Hidden"];
                            }

                            trans.Commit();
                            doc.Editor.WriteMessage("\nLayer alterado");
                            break;

                        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you already know a block name ("Teste"), you simply do:&lt;/P&gt;
&lt;P&gt;var layerTable=(LayerTable)tran.GetObject(db.LayerTableId, OpenMode.ForRead);&lt;/P&gt;
&lt;P&gt;LayerTableRecord layer;&lt;/P&gt;
&lt;P&gt;if (!layerTable.Has("Teste")&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layerTable.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer=new LayerTableRecord();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer.Name="Teste";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layerTable.Add(layer);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; tran.AddNewlyCreatedDBObject(....);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; layer=(LayerTableRecord)tran.GetObject(layerTable["Teste", OpenMode.ForWrite);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;// Change/Set layer's properties here&lt;/P&gt;
&lt;P&gt;layer.Color=...;&lt;/P&gt;
&lt;P&gt;layer.LineType=....;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because of the method Has(), there is no need to loop through LayerTable for each LayerTableRecord and test its name in order to find the layer in interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 19:23:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11497301#M11207</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2022-10-20T19:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11504865#M11208</link>
      <description>&lt;P&gt;Thanks for the collaboration, guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already found watt i need here.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 18:11:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11504865#M11208</guid>
      <dc:creator>seabrahenrique</dc:creator>
      <dc:date>2022-10-24T18:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11504980#M11209</link>
      <description>&lt;P&gt;If you found what you needed please mark the appropriate reply as the accepted solution. It helps others know that a solution has been found.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 19:12:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11504980#M11209</guid>
      <dc:creator>hippe013</dc:creator>
      <dc:date>2022-10-24T19:12:29Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11505810#M11210</link>
      <description>&lt;P&gt;Pls try this.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var documentManager = Application.DocumentManager;
            var currentDocument = documentManager.MdiActiveDocument;
            var database = currentDocument.Database;
            ObjectId layerId = ObjectId.Null;
            using (DocumentLock docLock = currentDocument.LockDocument())
            {
                using (Transaction acTrans = database.TransactionManager.StartTransaction())
                {
                    // Open the Layer table for read
                    LayerTable acLyrTbl;
                    acLyrTbl = acTrans.GetObject(database.LayerTableId,
                                                 OpenMode.ForRead) as LayerTable;
                            LayerTableRecord acLyrTblRec = new LayerTableRecord();
                            acLyrTblRec.Name = "somename";
                            LinetypeTable acLinTbl;
                            acLinTbl = acTrans.GetObject(database.LinetypeTableId,
                                                               OpenMode.ForRead) as LinetypeTable;
                            acLyrTbl.UpgradeOpen();
                            acLyrTbl.Add(acLyrTblRec);
                            acTrans.AddNewlyCreatedDBObject(acLyrTblRec, true);
                    acTrans.Commit();
                }
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 25 Oct 2022 05:42:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11505810#M11210</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-10-25T05:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11507947#M11211</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12396114"&gt;@MarkJamesRogolino&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you tested this code ?&lt;/P&gt;&lt;P&gt;what will happen if it's run twice ??&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:40:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11507947#M11211</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-10-25T19:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517523#M11212</link>
      <description>&lt;P&gt;Sorry, but i can't use your suggestion, see:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="seabrahenrique_0-1667068282872.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1133638iA61B1FF72AC1C67D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="seabrahenrique_0-1667068282872.png" alt="seabrahenrique_0-1667068282872.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The LayerTable object here does not have the .Item method... Again, someone know how can i get a layer by a name in C#?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In VBA i used to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim MyLayer as AcadLayer
MyLayer = ThisDrawing.Layer("NameOfLayer")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to do something similar in .NET? I mean, if i already have the name of layer or block, can i access that using this name?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 18:35:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517523#M11212</guid>
      <dc:creator>seabrahenrique</dc:creator>
      <dc:date>2022-10-29T18:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517583#M11213</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps something like this :&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public void GetLayerByName( )
{            
    var db = Application.DocumentManager.MdiActiveDocument.Database;
    var layerName = "MyLayer";

    using (var tr = db.TransactionManager.StartTransaction())
    {
        var layerTable = (LayerTable)tr.GetObject(
                        db.LayerTableId, OpenMode.ForRead);

        var layerRecord = (LayerTableRecord)tr.GetObject( 
                            layerTable[layerName], OpenMode.ForRead);

        // if you really want the ObjectID  ??

        var layerRecordOid = layerRecord.ObjectId;
                
        // . . . . 

    } 
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_kdub_0-1667072296230.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1133647i01C03C8E3C892387/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_kdub_0-1667072296230.png" alt="_kdub_0-1667072296230.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 19:38:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517583#M11213</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-10-29T19:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517615#M11214</link>
      <description>&lt;P&gt;Of course, we should check that the LayerTable actually does have a Layer of that name&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;. . . or this will happen :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="_kdub_0-1667074398102.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1133649i102543E581DAF3F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="_kdub_0-1667074398102.png" alt="_kdub_0-1667074398102.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public void GetLayerByName( )
{
    var db = Application.DocumentManager.MdiActiveDocument.Database;
    var layerName = "MyLayer_DoesNotExist";

    using ( var tr = db.TransactionManager.StartTransaction( ) )
    {
        var layerTable = (LayerTable)tr.GetObject(
                db.LayerTableId, OpenMode.ForRead);

        // ensure the layer exists !!
        if ( !layerTable.Has( layerName ) )
        {
            // show a message to the user.
            // then :
            return;
        }
        var layerRecord = (LayerTableRecord)tr.GetObject(
                    layerTable[layerName], OpenMode.ForRead);

        // if you really want the ObjectID  ??

        var layerRecordOid = layerRecord.ObjectId;

        // . . . .                 

    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 20:13:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517615#M11214</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-10-29T20:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Best pratices to create and edit layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517728#M11215</link>
      <description>&lt;P&gt;For what it's worth ;&lt;/P&gt;&lt;P&gt;This is about 17 years old and posted more as proof of concept than professional code.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=7918.0" target="_blank" rel="noopener"&gt;Making Layers with Particular Linetypes&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 22:14:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/best-pratices-to-create-and-edit-layer/m-p/11517728#M11215</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-10-29T22:14:57Z</dc:date>
    </item>
  </channel>
</rss>

