<?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 Betreff: Issue of copying entities to other layer in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361244#M12028</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see the code of "convertedLyrNm" used in this line:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#333399"&gt;string newlyrNm = &lt;FONT color="#FF6600"&gt;convertedLyrNm&lt;/FONT&gt;(lyrnm);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the crash ... please show the line where you code crashes during debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2022 06:13:20 GMT</pubDate>
    <dc:creator>Alfred.NESWADBA</dc:creator>
    <dc:date>2022-08-16T06:13:20Z</dc:date>
    <item>
      <title>Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359267#M12019</link>
      <description>&lt;P&gt;Hello everyone.&lt;/P&gt;&lt;P&gt;Now I am making an AutoCad Plugin copies all layers. But I made only copying layers module.&lt;/P&gt;&lt;P&gt;How can I make all the entities are copied to duplicated layers(e.g. New_&lt;EM&gt;layername&lt;/EM&gt;)?&lt;/P&gt;&lt;P&gt;Can someone help me? Thanks in after.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:08:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359267#M12019</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-15T09:08:08Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359293#M12020</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;one way going through each entity (if you really want to copy each single entity and not just content of modelspace):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;go through each BlockTableRecord in BlockTable,&lt;/LI&gt;
&lt;LI&gt;each BlockTableRecord has Entities,&lt;/LI&gt;
&lt;LI&gt;copy the entity,&lt;/LI&gt;
&lt;LI&gt;assign the copied entity the layer you like to have&lt;/LI&gt;
&lt;LI&gt;add this copied item to the BlockTableRecord.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you have another question or where is the point you can't continue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:20:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359293#M12020</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2022-08-15T09:20:36Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359306#M12021</link>
      <description>&lt;P&gt;Now I am making it with c# .net.&lt;/P&gt;&lt;P&gt;Do you have some similar sample code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:28:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359306#M12021</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-15T09:28:44Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359320#M12022</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there exist so many help already in www about how to copy objects using AutoCAD with .NET like this:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.com/search?client=firefox-b-d&amp;amp;q=autocad+.net+copy+objects" target="_blank" rel="noopener"&gt;&amp;gt;&amp;gt;&amp;gt;click&amp;lt;&amp;lt;&amp;lt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And no, I don't have such a code ready, so please start with your part and show then the code with the question where you can't continue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:31:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359320#M12022</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2022-08-15T09:31:21Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359326#M12023</link>
      <description>&lt;P&gt;okay, I will try, Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:34:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359326#M12023</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-15T09:34:43Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359344#M12024</link>
      <description>&lt;P&gt;my issue is copying between layers in one drawing.&lt;/P&gt;&lt;P&gt;but I can not find such help url.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:43:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359344#M12024</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-15T09:43:28Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359365#M12025</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;FONT color="#333399"&gt;&amp;gt;&amp;gt; my issue is copying between layers in one drawing.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;You first need to copy an entity ... as shown &lt;A href="http://docs.autodesk.com/ACD/2011/ENU/filesMDG/WS1a9193826455f5ff2566ffd511ff6f8c7ca-3f7e.htm" target="_blank" rel="noopener"&gt;&amp;gt;&amp;gt;&amp;gt;here&amp;lt;&amp;lt;&amp;lt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then, before adding the object back to the BlockTableRecord use&lt;/P&gt;
&lt;P&gt;Ent.Layer = "0" ... or the layername you want to assign it to (the layer has to exist, better/faster would be to assign it the LayerID)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 09:58:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11359365#M12025</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2022-08-15T09:58:38Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11360879#M12026</link>
      <description>&lt;P&gt;Hi, Thanks for your help. but there are some errors.&lt;/P&gt;&lt;P&gt;My code is as followings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Document acDoc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;Database acCurDb = acDoc.Database;&lt;BR /&gt;var objectIds = new ObjectIdCollection();&lt;BR /&gt;using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;BlockTable acBlkTbl;&lt;BR /&gt;acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,&lt;BR /&gt;OpenMode.ForRead) as BlockTable;&lt;BR /&gt;BlockTableRecord acBlkTblRec;&lt;BR /&gt;acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],&lt;BR /&gt;OpenMode.ForWrite) as BlockTableRecord;&lt;BR /&gt;var modelspace = (BlockTableRecord)acTrans.GetObject(&lt;BR /&gt;acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead);&lt;BR /&gt;foreach (ObjectId id in modelspace)&lt;BR /&gt;{&lt;BR /&gt;objectIds.Add(id);&lt;BR /&gt;Entity ent = (Entity)acTrans.GetObject(id, OpenMode.ForRead);&lt;BR /&gt;string lyrnm = ent.Layer.ToString();&lt;BR /&gt;string newlyrNm = convertedLyrNm(lyrnm);&lt;BR /&gt;Entity entcpy = ent.Clone() as Entity;&lt;BR /&gt;entcpy.Layer = newlyrNm;&lt;BR /&gt;acBlkTblRec.AppendEntity(entcpy);&lt;BR /&gt;acTrans.AddNewlyCreatedDBObject(entcpy, true);&lt;BR /&gt;}&lt;BR /&gt;acTrans.Commit();&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 00:28:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11360879#M12026</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T00:28:49Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11360967#M12027</link>
      <description>&lt;P&gt;I have to paste copied object to same position with source object. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 02:01:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11360967#M12027</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T02:01:57Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361244#M12028</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see the code of "convertedLyrNm" used in this line:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#333399"&gt;string newlyrNm = &lt;FONT color="#FF6600"&gt;convertedLyrNm&lt;/FONT&gt;(lyrnm);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the crash ... please show the line where you code crashes during debug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 06:13:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361244#M12028</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2022-08-16T06:13:20Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361424#M12029</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The RXObject.Clone() method does not deep clone the entity (i.e. does not copy the entity xdata and extension dictionary), you should use DeepCloneObjects instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming convertedLayerNames is a Dictionary&amp;lt;string, string&amp;gt; where each pair key is the old layer name and each pair value is the corresponding new layer name, assuming these new layers already exist in the drawing LayerTable, you can do something laike this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;        public void CopyModelSpaceEntitiesToNewLayer()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                // Deep clone all the entities in model space
                var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
                var modelSpace = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite);
                var ids = new ObjectIdCollection();
                foreach (ObjectId id in modelSpace)
                {
                    ids.Add(id);
                }
                var mapping = new IdMapping();
                db.DeepCloneObjects(ids, modelSpaceId, mapping, false);

                // change the layer of cloned entities
                foreach (IdPair pair in mapping)
                {
                    if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)
                    {
                        var entity = (Entity)tr.GetObject(pair.Value, OpenMode.ForWrite);
                        entity.Layer = convertedLayerNames[entity.Layer];
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 11:36:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361424#M12029</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-16T11:36:10Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361454#M12030</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="goldhorsemillion_0-1660698494300.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1104306i69F23060A928769B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="goldhorsemillion_0-1660698494300.png" alt="goldhorsemillion_0-1660698494300.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I think acTrans.Commit(); occurs an error.&lt;/P&gt;&lt;P&gt;I will expect good result.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 08:10:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361454#M12030</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T08:10:00Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361526#M12031</link>
      <description>&lt;P&gt;convertedLyrNm() function is only for getting layername to be copied.&lt;/P&gt;&lt;P&gt;I think acTrans.Commit(); occurs an error.&lt;/P&gt;&lt;P&gt;I will expect good result.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 09:02:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361526#M12031</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T09:02:41Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361529#M12032</link>
      <description>Thanks for your great help.&lt;BR /&gt;There was no error, but some entities are not pasted.&lt;BR /&gt;Anyway this will be allowable. Thanks again.</description>
      <pubDate>Tue, 16 Aug 2022 09:05:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361529#M12032</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T09:05:04Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361537#M12033</link>
      <description>PS. This function successfully copied about a little number of entities that I draw.&lt;BR /&gt;but many entities in opened document are not copied.</description>
      <pubDate>Tue, 16 Aug 2022 09:07:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361537#M12033</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T09:07:56Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361839#M12034</link>
      <description>&lt;P&gt;Take care with copy/paste of code snippets.&lt;/P&gt;
&lt;P&gt;By writing all the code yourself, you would certainly avoid this type of mistake:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
var modelspace = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForRead);&lt;/LI-CODE&gt;
&lt;P&gt;You open the model space table record twice, one time for write, the other time for read...&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 11:47:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361839#M12034</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-16T11:47:05Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361849#M12035</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/12396114"&gt;@MarkJamesRogolino&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;PS. This function successfully copied about a little number of entities that I draw.&lt;BR /&gt;but many entities in opened document are not copied.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can you elaborate about which kind of entities and/or attach a drawing sample containing such entities.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 11:49:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361849#M12035</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-16T11:49:19Z</dc:date>
    </item>
    <item>
      <title>Betreff: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361934#M12036</link>
      <description>&lt;P&gt;I can not copy areatable layer with your code.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 12:27:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11361934#M12036</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-16T12:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11362076#M12037</link>
      <description>&lt;P&gt;I cannot reproduce what you describe.&lt;/P&gt;
&lt;P&gt;From the tests I did, all the entities on the layer "_AREATABLE" are also copied.&lt;/P&gt;
&lt;P&gt;Try with this new code which moves the cloned entities of 700 units aong X axis.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public static void CopyModelSpaceEntitiesToNewLayer()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                // Deep clone all model space entities
                var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
                var modelSpace = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite);
                var ids = new ObjectIdCollection();
                foreach (ObjectId id in modelSpace)
                {
                    ids.Add(id);
                }
                var mapping = new IdMapping();
                db.DeepCloneObjects(ids, modelSpaceId, mapping, false);

                // change the layer of cloned entities
                foreach (IdPair pair in mapping)
                {
                    if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)
                    {
                        var entity = (Entity)tr.GetObject(pair.Value, OpenMode.ForWrite);
                        entity.Layer = convertedLayerNames[entity.Layer];

                        // move the cloned entity of 700 units along X axis
                        entity.TransformBy(Matrix3d.Displacement(Vector3d.XAxis * 700.0));
                    }
                }
                tr.Commit();
            }
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: Opening your file with the RECOVER command finds 3 errors.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 13:33:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11362076#M12037</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-08-16T13:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Issue of copying entities to other layer</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11364008#M12038</link>
      <description>&lt;P&gt;Thanks, gile.&lt;/P&gt;&lt;P&gt;Followings are my code.&lt;/P&gt;&lt;P&gt;public void CopyModelSpaceEntitiesToNewLayer()&lt;BR /&gt;{&lt;BR /&gt;var doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;var db = doc.Database;&lt;BR /&gt;using (var tr = db.TransactionManager.StartTransaction())&lt;BR /&gt;{&lt;BR /&gt;// Deep clone all the entities in model space&lt;BR /&gt;var modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);&lt;BR /&gt;var modelSpace = (BlockTableRecord)tr.GetObject(modelSpaceId, OpenMode.ForWrite);&lt;BR /&gt;var ids = new ObjectIdCollection();&lt;BR /&gt;foreach (ObjectId id in modelSpace)&lt;BR /&gt;{&lt;BR /&gt;ids.Add(id);&lt;BR /&gt;}&lt;BR /&gt;var mapping = new IdMapping();&lt;BR /&gt;db.DeepCloneObjects(ids, modelSpaceId, mapping, false);&lt;/P&gt;&lt;P&gt;// change the layer of cloned entities&lt;BR /&gt;foreach (IdPair pair in mapping)&lt;BR /&gt;{&lt;BR /&gt;if (pair.IsCloned &amp;amp;&amp;amp; pair.IsPrimary)&lt;BR /&gt;{&lt;BR /&gt;var entity = (Entity)tr.GetObject(pair.Value, OpenMode.ForWrite);&lt;BR /&gt;entity.Layer = convertedLyrNm(entity.Layer);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;tr.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Here I can not copy _AreaTable layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 08:50:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-of-copying-entities-to-other-layer/m-p/11364008#M12038</guid>
      <dc:creator>MarkJamesRogolino</dc:creator>
      <dc:date>2022-08-17T08:50:35Z</dc:date>
    </item>
  </channel>
</rss>

