<?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: Problems using IdMapping after running WblockCloneObjects in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12389058#M6548</link>
    <description>Thank you so much, I cant believe I didn't think of that. It's obvious now!</description>
    <pubDate>Mon, 20 Nov 2023 16:18:15 GMT</pubDate>
    <dc:creator>nshupeFMPE3</dc:creator>
    <dc:date>2023-11-20T16:18:15Z</dc:date>
    <item>
      <title>Problems using IdMapping after running WblockCloneObjects</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12388979#M6546</link>
      <description>&lt;P&gt;I've been testing moving selected items from one drawing to another.&lt;BR /&gt;I prompt the user to select what they would like to move.&lt;BR /&gt;I then move those objects to the "0" layer, as I dont want to bring layers from the source file to the destination.&lt;BR /&gt;I run this to move the objects over&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;static void CopyObjects(string destFileName, ObjectIdCollection idsToCopy)
{
    using (Database destDb = new Database(false, true))
    {
        destDb.ReadDwgFile(TemplatePath, System.IO.FileShare.Read, true, "");

        using (Transaction sourceTr = Active.Database.TransactionManager.StartOpenCloseTransaction())
        using (Transaction destTr = destDb.TransactionManager.StartOpenCloseTransaction())
        using(BlockTable destBt = destTr.GetObject(destDb.BlockTableId, OpenMode.ForRead, false, true) as BlockTable)
        {
            try
            {
                var mapping = new IdMapping();
                Active.Database.WblockCloneObjects(idsToCopy, destBt[BlockTableRecord.ModelSpace], mapping, DuplicateRecordCloning.Ignore,
                    false);

                _mapping = mapping;

                destTr.Commit();
                sourceTr.Commit();
            }
            catch
            {
                destTr.Abort();
                sourceTr.Abort();
            }
        }

        destDb.SaveAs(destFileName, DwgVersion.Current);
    }
    
}&lt;/LI-CODE&gt;&lt;P&gt;And then after I take the IdMapping and use Contains and Lookup to get the object id for the other side. But the ObjectId for the other side is not the same type?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I've tested by selecting just 1 polyline. And when I look through the mapping, I find one polyline on the source side of the pairs. But the destination side is of type Layer?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;CopyObjects(DESTINATION_FILE, ids);

using (Database destDb = new Database(false, true))
{
    destDb.ReadDwgFile(DESTINATION_FILE, FileShare.Read, true, "");

    using (Transaction destTr = destDb.TransactionManager.StartOpenCloseTransaction())
    {
        try
        {
            foreach (IdPair pair in _mapping)
            {
                Active.WriteMessage($"\nSource: {pair.Key.ObjectClass.DxfName} | Destination: {pair.Value.ObjectClass.DxfName}");
            }

            destTr.Commit();
        }
        catch
        {
            destTr.Abort();
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;How do I get the ObjectId for the corresponding object in the destination file?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 15:51:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12388979#M6546</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2023-11-20T15:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using IdMapping after running WblockCloneObjects</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12389038#M6547</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The ObjectId are unique per session and re-attributed at each new session. You get your IDMapping from a Database instance and try to use it in another one. This cannot work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to use this IDMapping within the scope of the using (Database destBb ...) statement where you get it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, if you want to be able to get the added objects after the database is closed, you have to use the objects Handles which are persistant per drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Handle[] _handles;
[...]
_handles = mapping
    .Cast&amp;lt;IdPair&amp;gt;()
    .Where(p =&amp;gt; p.IsCloned &amp;amp;&amp;amp; p.IsPrimary)
    .Select(p =&amp;gt; p.Value.Handle)
    .ToArray();&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 16:15:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12389038#M6547</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-11-20T16:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using IdMapping after running WblockCloneObjects</title>
      <link>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12389058#M6548</link>
      <description>Thank you so much, I cant believe I didn't think of that. It's obvious now!</description>
      <pubDate>Mon, 20 Nov 2023 16:18:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problems-using-idmapping-after-running-wblockcloneobjects/m-p/12389058#M6548</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2023-11-20T16:18:15Z</dc:date>
    </item>
  </channel>
</rss>

