<?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: How do I copy a layer with C#? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608908#M28723</link>
    <description>&lt;P&gt;Thanks.&amp;nbsp; These posts got me to where I needed to go.&amp;nbsp; Here is my code snippet that is doing exactly what I needed done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;using&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (Transaction lTrans = acCurDb.TransactionManager.StartTransaction())&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;string&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; MtrLayNam = ulLayNam.Replace(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_UNIT"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_MTR"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LayerTable lTbl;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lTbl = lTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTable;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//SetUnitLayerSibling(acCurDb, acDoc, ulLayNam);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (lTbl.Has(MtrLayNam) == &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;false&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;LayerTableRecord lRec;&lt;/P&gt;
&lt;P&gt;lTbl.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lRec = lTrans.GetObject(lTbl[ulLayNam], OpenMode.ForRead).Clone() &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTableRecord;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lRec.Name = MtrLayNam;&lt;/P&gt;
&lt;P&gt;lTbl.Add(lRec);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lTrans.AddNewlyCreatedDBObject(lRec, &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;true&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lTrans.Commit();&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;acCurDb.Clayer = lTbl[MtrLayNam];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//lTrans.Commit();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!!&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2017 16:52:22 GMT</pubDate>
    <dc:creator>sonny3g</dc:creator>
    <dc:date>2017-12-08T16:52:22Z</dc:date>
    <item>
      <title>How do I copy a layer with C#?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608288#M28720</link>
      <description>&lt;P&gt;I need to "clone" or copy a layer in a drawing and then rename it use C#.&amp;nbsp; What I am starting with is the layer name of a MLeader object that I need to create a new MLeader object on a different layer with the same properties as the layer the original MLeader object is located on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Right now, I have the layer name of the existing MLeader and have created the new layer name.&amp;nbsp; I am able to change to the new layer if it exists, but if it does not, I have to create the new layer and then change to it before creating the new MLeader object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am struggling with retrieving the layer color from the original MLeader object layer.&amp;nbsp; The MLeader color is by layer, so I have to get the color from the layer itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;[CommandMethod(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"SetUnitLayerSibling"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)]&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;private&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;static&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Consolas" size="2"&gt;void&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; SetUnitLayerSibling(Database acCurDb, Document acDoc, &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;string&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; ulLayNam) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;using&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (Transaction lTrans = acCurDb.TransactionManager.StartTransaction())&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;// Getting and setting MLeader layer information&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;String MtrLayName;&lt;/P&gt;
&lt;P&gt;String tag;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; MtrLayName = ulLayNam.Replace(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_UNIT"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_MTR"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LayerTable lTbl;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lTbl = lTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTable;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (lTbl.Has(MtrLayName) == &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;true&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;// Set the layer &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;acCurDb.Clayer = lTbl[MtrLayName];&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;else&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;// Get unit layer parameters&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LayerTableRecord ulRec;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;// Clone unit layer and re-name&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTableRecord lTblRec = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;new&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTableRecord();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lTblRec.Color =&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;lTrans.Commit();&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 14:13:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608288#M28720</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2017-12-08T14:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I copy a layer with C#?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608625#M28721</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;give this a try.&lt;/P&gt;&lt;P&gt;The LayerTableRecord has a Clone Methode which you can use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;LayerTableRecord m_LayerTableRecord = new LayerTableRecord();
LayerTableRecord m_LayerTableRecordCloned = null;
m_LayerTableRecordCloned = (LayerTableRecord)m_LayerTableRecord.Clone();&lt;/PRE&gt;&lt;P&gt;Regards Jürgen&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 15:38:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608625#M28721</guid>
      <dc:creator>Juergen_Becker</dc:creator>
      <dc:date>2017-12-08T15:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I copy a layer with C#?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608781#M28722</link>
      <description>&lt;P&gt;&lt;FONT face="georgia,palatino" size="3"&gt;Hi,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="georgia,palatino" size="3"&gt;Manual method here. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        public static void CloneLayerName ()
        {
            Document doc = App.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            String Old = "OldLayer";
            String New = "NewLayer";

            using (Transaction lTrans = db.TransactionManager.StartTransaction())
            {
                LayerTable lTbl = (LayerTable)lTrans.GetObject(db.LayerTableId, OpenMode.ForWrite);
                if (lTbl.Has(Old) &amp;amp;&amp;amp; !lTbl.Has(New))
                {
                    using (LayerTableRecord lay = new LayerTableRecord())
                    {
                        LayerTableRecord Oldlayer = (LayerTableRecord)lTbl[Old].GetObject(OpenMode.ForRead);
                        lay.Name = New;
                        lay.Color = Oldlayer.Color;
                        lay.LineWeight = Oldlayer.LineWeight;
                        lay.LinetypeObjectId = Oldlayer.LinetypeObjectId;
                        lay.Description = Oldlayer.Description;
                        lTbl.Add(lay);
                    }   
                }
                lTrans.Commit();               
            }
           
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:19:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608781#M28722</guid>
      <dc:creator>_Tharwat</dc:creator>
      <dc:date>2017-12-08T16:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I copy a layer with C#?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608908#M28723</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; These posts got me to where I needed to go.&amp;nbsp; Here is my code snippet that is doing exactly what I needed done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;using&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (Transaction lTrans = acCurDb.TransactionManager.StartTransaction())&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;string&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; MtrLayNam = ulLayNam.Replace(&lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_UNIT"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#a31515" face="Consolas" size="2"&gt;"_MTR"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LayerTable lTbl;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lTbl = lTrans.GetObject(acCurDb.LayerTableId, OpenMode.ForRead) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTable;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//SetUnitLayerSibling(acCurDb, acDoc, ulLayNam);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; (lTbl.Has(MtrLayNam) == &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;false&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;LayerTableRecord lRec;&lt;/P&gt;
&lt;P&gt;lTbl.UpgradeOpen();&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lRec = lTrans.GetObject(lTbl[ulLayNam], OpenMode.ForRead).Clone() &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;as&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; LayerTableRecord;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lRec.Name = MtrLayNam;&lt;/P&gt;
&lt;P&gt;lTbl.Add(lRec);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt; lTrans.AddNewlyCreatedDBObject(lRec, &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;true&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lTrans.Commit();&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;acCurDb.Clayer = lTbl[MtrLayNam];&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//lTrans.Commit();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2017 16:52:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-copy-a-layer-with-c/m-p/7608908#M28723</guid>
      <dc:creator>sonny3g</dc:creator>
      <dc:date>2017-12-08T16:52:22Z</dc:date>
    </item>
  </channel>
</rss>

