<?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: Can't turn on viewport after cloning in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7301737#M30112</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to clone an existing viewport on a layout, so I can split the viewport in t two parts. However when I clone a viewport using Viewport.Clone() and erase the original with Viewport.Erase(), I can't turn the cloned viewport on. When I try to turn it on via the properties panel in AutoCAD it gives me the following error:&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;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clone() can't be used to produce&amp;nbsp;a usable copy of any type of object.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clone does a 'shallow' copy that does not also clone owned objects, which is why you are having the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To copy an object, you should&amp;nbsp;use the &lt;STRONG&gt;Database.DeepCloneObjects()&lt;/STRONG&gt; method.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2017 14:52:36 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2017-08-15T14:52:36Z</dc:date>
    <item>
      <title>Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7301131#M30111</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to clone an existing viewport on a layout, so I can split the viewport in t two parts. However when I clone a viewport using Viewport.Clone() and erase the original with Viewport.Erase(), I can't turn the cloned viewport on. When I try to turn it on via the properties panel in AutoCAD it gives me the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 200px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/390020i37564874A3596343/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using AutoCAD 2018 on Windows 10. The error can be reproduced by doing the following steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Compile code&lt;/LI&gt;&lt;LI&gt;Load DLLvia NETLOAD&lt;/LI&gt;&lt;LI&gt;Open drawing (acadiso)&lt;/LI&gt;&lt;LI&gt;Use CLONEVIEWPORT on a floating viewport on one of the layouts&lt;/LI&gt;&lt;LI&gt;Try to toggle the 'On'-property in the properties panel&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also noticed some other strange behaviour, when I don't erase the original viewport I can change any of the viewport specific properties and the same changes get applied to the cloned one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using ARXDBG I can see that the Number (DXF 69) is the same on both objects. Is this normal?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone give help me solve this issue or give me any hints on how I should try to workaround this error and can clone a viewport?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(Buggy.Repro.CloneViewport))]
namespace Buggy.Repro
{
    class CloneViewport
    {
        [CommandMethod("CLONEVIEWPORT")]
        public void CloneViewportCommand()
        {
            Document document = Application.DocumentManager.CurrentDocument;
            Editor editor = document.Editor;
            Database database = document.Database;

            PromptEntityOptions vpOptions = new PromptEntityOptions("Pick a viewport: ");
            vpOptions.SetRejectMessage("Invalid object.");
            vpOptions.AddAllowedClass(typeof(Viewport), true);
            PromptEntityResult vpResult = editor.GetEntity(vpOptions);
            if (vpResult.Status != PromptStatus.OK)
                return;

            using (Transaction tr = database.TransactionManager.StartTransaction())
            {
                Viewport viewport = (Viewport)tr.GetObject(vpResult.ObjectId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(viewport.BlockId, OpenMode.ForWrite);

                Viewport copiedVp = (Viewport)viewport.Clone();
                copiedVp.Color = Color.FromRgb(0, 0, 255); // mark copy
                copiedVp.On = true;

                btr.AppendEntity(copiedVp);
                tr.AddNewlyCreatedDBObject(copiedVp, true);

                viewport.Erase();

                tr.Commit();
            }
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Aug 2017 11:35:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7301131#M30111</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-15T11:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7301737#M30112</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to clone an existing viewport on a layout, so I can split the viewport in t two parts. However when I clone a viewport using Viewport.Clone() and erase the original with Viewport.Erase(), I can't turn the cloned viewport on. When I try to turn it on via the properties panel in AutoCAD it gives me the following error:&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;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clone() can't be used to produce&amp;nbsp;a usable copy of any type of object.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Clone does a 'shallow' copy that does not also clone owned objects, which is why you are having the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To copy an object, you should&amp;nbsp;use the &lt;STRONG&gt;Database.DeepCloneObjects()&lt;/STRONG&gt; method.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 14:52:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7301737#M30112</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-15T14:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302200#M30113</link>
      <description>&lt;P&gt;Thanks for your reply! I've tried to use both Database.DeepCloneObjects() and Entity.DeepClone(). Both yield the same result as just a shallow copy.&lt;/P&gt;&lt;P&gt;I am beginning to think that the problem might be that AutoCAD doesn't generate a new "Number" (DXF 68 / 69?) for the cloned viewport. Which seems alright because, well, it is a clone after all.&lt;/P&gt;&lt;P&gt;Anyway it's like&amp;nbsp;the two (cloned en original) viewports reference the same objects / tables and when you erase one of the viewports the referenced objects get erased, but the references don't get updated / kept for the remaining viewport. I haven't been able to find a way to generate these objects / ids for a new viewport except for, initializing a viewport. But then you have to "manually" sync all the properties between the clone and the original&amp;nbsp;&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://forums.autodesk.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you or someone else knows a way around this?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 17:22:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302200#M30113</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-15T17:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302395#M30114</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Thanks for your reply! I've tried to use both Database.DeepCloneObjects() and Entity.DeepClone(). Both yield the same result as just a shallow copy.&lt;/P&gt;&lt;P&gt;I am beginning to think that the problem might be that AutoCAD doesn't generate a new "Number" (DXF 68 / 69?) for the cloned viewport. Which seems alright because, well, it is a clone after all.&lt;/P&gt;&lt;P&gt;Anyway it's like&amp;nbsp;the two (cloned en original) viewports reference the same objects / tables and when you erase one of the viewports the referenced objects get erased, but the references don't get updated / kept for the remaining viewport. I haven't been able to find a way to generate these objects / ids for a new viewport except for, initializing a viewport. But then you have to "manually" sync all the properties between the clone and the original&amp;nbsp;&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://forums.autodesk.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you or someone else knows a way around this?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;DeepCloneObjects() &lt;EM&gt;does not&lt;/EM&gt; produce the same result as Clone() (a shallow copy).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you observed ('it's like the two (cloned en original) viewports reference the same objects /tables'), means the copy of the viewport is a shallow copy.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;More precisely, it probably means that both the clone and original viewports have the same extension dictionary, because Clone() does a shallow copy that does not clone the object's extension dictionary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing you must do, is activate the layout tab containing the viewport at least once before trying to copy it, because that's when the initialization of the&amp;nbsp;layout happens. If you tried it on a new drawing that has never had the Layout containing the viewport activated, it will also probably fail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some extension methods/helpers that simplify using the DeepCloneObjects() method (by just delegating to the COM API):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;

namespace MyNamespace
{
   public static class MyExtensions
   {
      /// &amp;lt;summary&amp;gt;
      /// Copies the given entity and appends it to the
      /// same owner space.
      /// 
      /// The entity cannot be opened via a regular transaction.
      /// It can be opened via an OpenCloseTransaction.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="source"&amp;gt;The Entity to be copied&amp;lt;/param&amp;gt;
      /// &amp;lt;returns&amp;gt;The ObjectId of the copy of the given Entity&amp;lt;/returns&amp;gt;

      public static ObjectId Copy(this Entity source)
      {
         if(source == null)
            throw new ArgumentNullException("source");
         if(source.IsTransactionResident)
            throw new InvalidOperationException("source is transaction-resident");
         return DBObject.FromAcadObject(((dynamic) source.AcadObject).Copy());
      }

      /// &amp;lt;summary&amp;gt;
      /// Copies the entity referenced by the given ObjectId,
      /// appends it to the same owner space, and optionally
      /// transforms it by the given transformation matrix.
      /// The entity referenced by the source ObjectId should 
      /// not be open when this method is called.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="source"&amp;gt;The ObjectId of the source entity&amp;lt;/param&amp;gt;
      /// &amp;lt;param name="transform"&amp;gt;The transformation matrix (optional)&amp;lt;/param&amp;gt;
      /// &amp;lt;returns&amp;gt;The ObjectId of the copy of the given Entity&amp;lt;/returns&amp;gt;
      
      public static ObjectId Copy(this ObjectId source, Matrix3d? transform = null)
      {
         if(source.IsNull || source.Database == null || source.IsErased || ! source.IsValid)
            throw new ArgumentException("Invalid ObjectId");
         if(!source.IsTypeOf&amp;lt;Entity&amp;gt;())
            throw new ArgumentException("Requires the ObjectId of an Entity");
         using(var trans = new OpenCloseTransaction())
         {
            ObjectId id = Copy((Entity) trans.GeTClass(source, OpenMode.ForRead));
            if(transform.HasValue)
            {
               Entity entity = (Entity) trans.GeTClass(id, OpenMode.ForWrite);
               entity.TransformBy(transform.Value);
            }
            trans.Commit();
            return id;
         }
      }

   }

   public static class RXClass&amp;lt;T&amp;gt; where T : RXObject
   {
      public static readonly RXClass Value = RXClass.GetClass(typeof(T));
   }
   
   public static class MyObjectIdExtensions
   {
      public static bool IsTypeOf&amp;lt;T&amp;gt;(this ObjectId source) where T : DBObject
      {
         return source.ObjectClass != null &amp;amp;&amp;amp; source.ObjectClass.IsDerivedFrom(RXClass&amp;lt;T&amp;gt;.Value);
      }
   }

   public static class CopyExampleCommands
   {
      [CommandMethod("MYCOPY")]
      public static void MyCopyCommand()
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         Editor ed = doc.Editor;
         PromptEntityResult res = ed.GetEntity("\nSelect object to copy: ");
         if(res.Status != PromptStatus.OK)
            return;
         ObjectId id = res.ObjectId;
         /// Copy the selected entity and translate by 2,2 units:
         id.Copy(Matrix3d.Displacement(new Vector3d(2, 2, 0)));
      }
   }

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 18:57:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302395#M30114</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-15T18:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302510#M30115</link>
      <description>&lt;P&gt;oops... I was trying out my new Chrome search/replace extension when editing that reply and messed it up badly....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;

namespace MyNamespace
{
   public static class MyExtensions
   {
      /// &amp;lt;summary&amp;gt;
      /// Copies the given entity and appends it to the
      /// same owner space.
      /// 
      /// The entity cannot be opened via a regular transaction.
      /// It can be opened via an OpenCloseTransaction.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="source"&amp;gt;The Entity to be copied&amp;lt;/param&amp;gt;
      /// &amp;lt;returns&amp;gt;The ObjectId of the copy of the given Entity&amp;lt;/returns&amp;gt;

      public static ObjectId Copy(this Entity source)
      {
         if(source == null)
            throw new ArgumentNullException("source");
         if(source.IsTransactionResident)
            throw new InvalidOperationException("source is transaction-resident");
         return DBObject.FromAcadObject(((dynamic) source.AcadObject).Copy());
      }

      /// &amp;lt;summary&amp;gt;
      /// Copies the entity referenced by the given ObjectId,
      /// appends it to the same owner space, and optionally
      /// transforms it by the given transformation matrix.
      /// The entity referenced by the source ObjectId should 
      /// not be open when this method is called.
      /// &amp;lt;/summary&amp;gt;
      /// &amp;lt;param name="source"&amp;gt;The ObjectId of the source entity&amp;lt;/param&amp;gt;
      /// &amp;lt;param name="transform"&amp;gt;The transformation matrix (optional)&amp;lt;/param&amp;gt;
      /// &amp;lt;returns&amp;gt;The ObjectId of the copy of the given Entity&amp;lt;/returns&amp;gt;
      
      public static ObjectId Copy(this ObjectId source, Matrix3d? transform = null)
      {
         if(source.IsNull || source.Database == null || source.IsErased || ! source.IsValid)
            throw new ArgumentException("Invalid ObjectId");
         if(!source.ObjectClass.IsDerivedFrom(RXClass&amp;lt;Entity&amp;gt;.Value))
            throw new ArgumentException("Requires the ObjectId of an Entity");
         using(var trans = new OpenCloseTransaction())
         {
            ObjectId id = Copy((Entity) trans.GetObject(source, OpenMode.ForRead));
            if(transform.HasValue)
            {
               Entity entity = (Entity) trans.GetObject(id, OpenMode.ForWrite);
               entity.TransformBy(transform.Value);
            }
            trans.Commit();
            return id;
         }
      }

   }

   public static class RXClass&amp;lt;T&amp;gt; where T : RXObject
   {
      public static readonly RXClass Value = RXObject.GetClass(typeof(T));
   }
   
   public static class CopyExampleCommands
   {
      [CommandMethod("MYCOPY")]
      public static void MyCopyCommand()
      {
         Document doc = Application.DocumentManager.MdiActiveDocument;
         Editor ed = doc.Editor;
         PromptEntityResult res = ed.GetEntity("\nSelect object to copy: ");
         if(res.Status != PromptStatus.OK)
            return;
         ObjectId id = res.ObjectId;
         /// Copy the selected entity and translate by 2,2 units:
         id.Copy(Matrix3d.Displacement(new Vector3d(2, 2, 0)));
      }
   }

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 19:12:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7302510#M30115</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-15T19:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7303676#M30116</link>
      <description>&lt;P&gt;Thank you for your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you explain the difference between your method (copying the dynamic object and creating a new AcadObject), Database.DeepCloneObjects() and DBObject.DeepClone()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried some experiments, but I'm having some troubles. Somehow in the command below the third one (DBObject.DeepClone()) does add a new instance to the BlockTableRecord, but isn't visible in AutoCAD. I can see it with ARXDBG, but not visually.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("CLONEVIEWPORT")]
        public void CloneViewportCommand()
        {
            Document document = Application.DocumentManager.CurrentDocument;
            Editor editor = document.Editor;
            Database database = document.Database;

            PromptEntityOptions vpOptions = new PromptEntityOptions("Pick a viewport: ");
            vpOptions.SetRejectMessage("Invalid object.");
            vpOptions.AddAllowedClass(typeof(Viewport), true);
            PromptEntityResult vpResult = editor.GetEntity(vpOptions);
            if (vpResult.Status != PromptStatus.OK)
                return;

            using (Transaction tr = database.TransactionManager.StartTransaction())
            {
                Viewport viewport = (Viewport)tr.GetObject(vpResult.ObjectId, OpenMode.ForRead);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(viewport.BlockId, OpenMode.ForWrite);

                Action&amp;lt;ObjectId, Color&amp;gt; mark = (objId, color) =&amp;gt;
                {
                    Viewport vp = (Viewport)tr.GetObject(objId, OpenMode.ForWrite);
                    vp.Color = color;
                };

                // Clone by COM?
                ObjectId newId = DBObject.FromAcadObject(((dynamic)viewport.AcadObject).Copy());
                mark(newId, Color.FromRgb(255, 0, 0));

                // DeepClone by Database
                ObjectIdCollection collection = new ObjectIdCollection(new[] { viewport.Id });
                IdMapping mapping = new IdMapping();
                database.DeepCloneObjects(collection, viewport.BlockId, mapping, false);
                mark(mapping[viewport.Id].Value, Color.FromRgb(0, 255, 0));

                // DeepClone by DBObject
                mapping = new IdMapping();
                DBObject newVp = viewport.DeepClone(btr, mapping, true);
                tr.AddNewlyCreatedDBObject(newVp, true);
                mark(newVp.ObjectId, Color.FromRgb(0, 0, 255));

                // Erase original
                viewport.Erase();

                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Aug 2017 06:30:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7303676#M30116</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-16T06:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can't turn on viewport after cloning</title>
      <link>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7304348#M30117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Thank you for your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you explain the difference between your method (copying the dynamic object and creating a new AcadObject), Database.DeepCloneObjects() and DBObject.DeepClone()?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried some experiments, but I'm having some troubles. Somehow in the command below the third one (DBObject.DeepClone()) does add a new instance to the BlockTableRecord, but isn't visible in AutoCAD. I can see it with ARXDBG, but not visually.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That's because you can't use DeepClone() to copy something. It requires DeepCloneObjects().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DeepClone() (or more precisely, the native API it wraps) was intended to be called internally, and the native API is marked as virtual so that custom objects can override it and perform whatever operations the need to when they are deep-cloned.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Copying an object involves more than just a call to DeepClone() (which DeepCloneObjects() calls on each object you pass it). It requires the IdMapping to be properly initialized for the type of deep-clone operation. You can examine the IdMapping that you create and pass to DeepCloneObjects() before and after you call the latter, and you'll see that the IdMapping's properties have changed, because DeepCloneObjects() is setting them to the required values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In a deep-clone operation, the call to DeepClone() is just one step. There is another step that can't be done until all objects have been cloned, which is the 'translation phase', where ObjectId references contained in the cloned objects must be translated (depending on the type of cloning done, and whether referenced objects are also being cloned).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should probably read up on deep-cloning in the native ObjectARX developer's guide, as it covers the topic in great detail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't waste time trying to figure out why DeepClone() doesn't work, because it wasn't designed to be used for what you're trying to use it to do.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 12:01:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/can-t-turn-on-viewport-after-cloning/m-p/7304348#M30117</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2017-08-16T12:01:04Z</dc:date>
    </item>
  </channel>
</rss>

