<?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: I'm trying to create multiple layers in C#. Each layer should have a unique description, but currently, the description is always the same as the layer name. Could you help me figure out ? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693137#M85288</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AravinthPichamani_0-1750657628064.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1545622iC5DB806C90AE3A98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AravinthPichamani_0-1750657628064.png" alt="AravinthPichamani_0-1750657628064.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jun 2025 05:47:20 GMT</pubDate>
    <dc:creator>Aravinth.Pichamani</dc:creator>
    <dc:date>2025-06-23T05:47:20Z</dc:date>
    <item>
      <title>I'm trying to create multiple layers in C#. Each layer should have a unique description, but currently, the description is always the same as the layer name. Could you help me figure out ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693135#M85287</link>
      <description>&lt;LI-CODE lang="csharp"&gt; [CommandMethod("Multilayer")]
 public void CreateCustomLayersFixed()
 {
     Document doc = Application.DocumentManager.MdiActiveDocument;
     Editor editor = doc.Editor;
     Database database = doc.Database;
     ObjectId layerId = database.LayerTableId;

     // Sample list: (Layer Name, Description, Color Index)
     List&amp;lt;(string name, string description, short colorIndex)&amp;gt; layersList = new List&amp;lt;(string name, string description, short colorIndex)&amp;gt;
     {
                   ("C-NTWK-ELE3-CABL-AERL-E", "Existing Aerial Cable", 55),
                  ("C-NTWK-ELE3-CABL-AERL-P", "Proposed Aerial Cable", 4),
                 ("C-NTWK-ELE3-CABL-AERL-T", "Temporary Aerial Cable", 160),
     };

     using (Transaction tr = database.TransactionManager.StartTransaction())
     {
         //  Register "LayerDescriptions" for XData
         RegAppTable regAppTable = tr.GetObject(database.RegAppTableId, OpenMode.ForRead) as RegAppTable;
         if (!regAppTable.Has("LayerDescriptions"))
         {
             regAppTable.UpgradeOpen();
             RegAppTableRecord regAppRecord = new RegAppTableRecord
             {
                 Name = "LayerDescriptions"
             };
             regAppTable.Add(regAppRecord);
             tr.AddNewlyCreatedDBObject(regAppRecord, true);
         }

         LayerTable layerTable = tr.GetObject(layerId, OpenMode.ForRead) as LayerTable;

         foreach (var lay in layersList)
         {
             string name = lay.name;
             string description = lay.description;
             short colorIndex = lay.colorIndex;

             editor.WriteMessage($"\nProcessing: Name='{name}', Description='{description}'"); // DEBUG

             if (!layerTable.Has(name))
             {
                 layerTable.UpgradeOpen();

                 LayerTableRecord newLayer = new LayerTableRecord
                 {
                     Name = name,
                     Color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex),
                     Description = description
                 };

                 // Attach XData description
                 ResultBuffer xdata = new ResultBuffer(
                     new TypedValue((int)DxfCode.ExtendedDataRegAppName, "LayerDescriptions"),
                     new TypedValue((int)DxfCode.ExtendedDataAsciiString, description)
                 );
                 newLayer.XData = xdata;

                 layerTable.Add(newLayer);
                 tr.AddNewlyCreatedDBObject(newLayer, true);

                 editor.WriteMessage($"\n Created layer: {name} (Color: {colorIndex}, Desc: {description})");
             }
             else
             {
                 LayerTableRecord existingLayer = (LayerTableRecord)tr.GetObject(layerTable[name], OpenMode.ForWrite);
                 existingLayer.Description = description;
                 editor.WriteMessage($"\nUpdated existing layer: {name} (Desc: {description})");

             }
         }
         tr.Commit();
     }
 }&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 23 Jun 2025 05:46:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693135#M85287</guid>
      <dc:creator>Aravinth.Pichamani</dc:creator>
      <dc:date>2025-06-23T05:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: I'm trying to create multiple layers in C#. Each layer should have a unique description, but currently, the description is always the same as the layer name. Could you help me figure out ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693137#M85288</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AravinthPichamani_0-1750657628064.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1545622iC5DB806C90AE3A98/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AravinthPichamani_0-1750657628064.png" alt="AravinthPichamani_0-1750657628064.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jun 2025 05:47:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693137#M85288</guid>
      <dc:creator>Aravinth.Pichamani</dc:creator>
      <dc:date>2025-06-23T05:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: I'm trying to create multiple layers in C#. Each layer should have a unique description, but currently, the description is always the same as the layer name. Could you help me figure out ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693183#M85289</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try setting the description after having added the new layer to the Database.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (!layerTable.Has(name))
{
    layerTable.UpgradeOpen();

    LayerTableRecord newLayer = new LayerTableRecord
    {
        Name = name,
        Color = Color.FromColorIndex(ColorMethod.ByAci, colorIndex)
    };

    layerTable.Add(newLayer);
    tr.AddNewlyCreatedDBObject(newLayer, true);
 
    newLayer.Description = description;

    editor.WriteMessage($"\n Created layer: {name} (Color: {colorIndex}, Desc: {description})");
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 23 Jun 2025 06:18:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-m-trying-to-create-multiple-layers-in-c-each-layer-should-have/m-p/13693183#M85289</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2025-06-23T06:18:07Z</dc:date>
    </item>
  </channel>
</rss>

