Author Topic: Clone() DeepClone()  (Read 2460 times)

0 Members and 1 Guest are viewing this topic.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Clone() DeepClone()
« on: July 11, 2015, 08:18:10 PM »
What does clone() and DeepClone() do? Having trouble finding anything in the developer guides.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Clone() DeepClone()
« Reply #1 on: July 11, 2015, 11:19:44 PM »

From arxdev.chm
Quote

Using clone() versus deepClone()

The AcRxObject::clone() function clones a single object. The AcDbObject::deepClone() function clones the object and any objects owned by that object. The deepClone() function also translates the cloned object's references.

In general, the deepClone() function is the safer of the two functions. If you are cloning a simple object such as an ellipse, the two functions may be equivalent. But if you are cloning a complex object such as a polyline, the clone() function isn't adequate because it clones only the polyline object. With the deepClone() function, you clone the polyline as well as its vertices.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Clone() DeepClone()
« Reply #2 on: July 13, 2015, 08:43:15 PM »
Thanks kerry..."clone" as in "copy"? Does this work with any entity in autocad?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Clone() DeepClone()
« Reply #3 on: July 13, 2015, 08:49:09 PM »

I'm not conversant with the particulars ... I'd need to do some study and run a few tests.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Clone() DeepClone()
« Reply #4 on: July 14, 2015, 01:34:34 AM »
Thanks kerry..."clone" as in "copy"? Does this work with any entity in autocad?
Alien, my understanding of the purpose of clone/deepclone is to create a copy of an object. Clone would only include simple properties that are doubles, ints, strings, etc. Deepclone would include the object properties that are also objects (vertices, xData, etc).


Code: [Select]
Polyline thePoly = myPolyline;

Polyline newPoly = myPolyline.deepclone();

thePoly is just  a reference to myPolyline, any changes you make to thePoly will effect myPolyline

newPoly is a new item, you can change and manipulate newpoly and not effect myPolyline. I've not used either of these methods, but I'd imagine you'd need to add the newPoly to modelspace to actually put it in the drawing.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Clone() DeepClone()
« Reply #5 on: July 14, 2015, 08:44:28 AM »
In a clone operation if one of its properties is a class it will just copy the pointer which is just an address to the location of the object.
In deepclone it will follow the pointer and create a whole new object and set its property to a pointer that's the new copy of object.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Clone() DeepClone()
« Reply #6 on: July 14, 2015, 09:03:17 AM »
Following up on Jeff's response.  If I clone an object in one of the verticals, none of the object styles will get cloned.  However if i deepclone it then it will also copy any styles associated with the object.  For instance in AutoCAD MEP it will copy any property sets that are attached to the object and make sure that they are all on the new object as well.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Clone() DeepClone()
« Reply #7 on: July 14, 2015, 10:58:08 AM »
Following up Keith's response I guess in AutoCAD's terms its a little different where, when cloning between drawings it has to follow hard pointers and copy them into the drawings, and in same drawing it will not  truly do a deepclone and where it would clone a entities layer but does a shallow clone.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Clone() DeepClone()
« Reply #8 on: July 14, 2015, 11:00:22 AM »
 :2funny: :2funny: :2funny: :2funny: :2funny: :2funny:
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: Clone() DeepClone()
« Reply #9 on: July 24, 2015, 01:45:33 AM »
Appreciate all the info peeps. Thank you :)