Author Topic: Deep Cloning  (Read 7910 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Deep Cloning
« Reply #15 on: October 07, 2010, 11:14:41 AM »
Good to hear Jurg, you're welcome.  I've learned a lot from your code, so it's nice I could pay you back some.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Deep Cloning
« Reply #16 on: October 07, 2010, 02:02:02 PM »
Hi,

Here's a vlisp code which creates a block definition from a selection set, an insertion point and a name:

Edited code: I forgot *acdoc* and *blocks* global variables
Code: [Select]
(defun c:ss2blk    (/ name ss lst ins blk)
  (vl-load-com)
  (or *acdoc*
      (setq *acdoc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  )
  (or *blocks* (setq *blocks* (vla-get-Blocks *acdoc*)))
  (if
    (and
      (setq ss (ssget))
      (setq ins (getpoint "\nSpecify insertion point: "))
    )
     (progn
       (setq name (getstring "\nEnter block name: "))
       (while (tblsearch "BLOCK" name)
     (setq
       name
        (getstring (strcat "\nA block named '"
                   name
                   "' already exists\nEnter block name: "
               )
        )
     )
       )
       (vlax-for o (setq ss (vla-get-ActiveSelectionSet *acdoc*))
     (setq lst (cons o lst))
       )
       (vla-delete ss)
       (setq blk (vla-Add *blocks* (vlax-3d-point '(0. 0. 0.)) name))
       (setq lst (vlax-invoke *acdoc* 'CopyObjects lst blk))
       (foreach    o lst
     (vla-move o
           (vlax-3d-point (trans ins 1 0))
           (vlax-3d-point '(0. 0. 0.))
     )
       )
     )
  )
  (princ)
)
« Last Edit: October 07, 2010, 02:52:09 PM by gile »
Speaking English as a French Frog

jbuzbee

  • Swamp Rat
  • Posts: 851
Re: Deep Cloning
« Reply #17 on: October 08, 2010, 03:12:34 PM »
Deep Cloning?

That's done on Kamino, a few parsecs beyong the outer rim . . . they're "cloners" ya know  :wink:
James Buzbee
Windows 8

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Deep Cloning
« Reply #18 on: October 08, 2010, 03:15:13 PM »
Deep Cloning?

That's done on Kamino, a few parsecs beyong the outer rim . . . they're "cloners" ya know  :wink:

 :lmao:  :lmao:

Jeff H

  • Needs a day job
  • Posts: 6144
Re: Deep Cloning
« Reply #19 on: November 10, 2010, 01:31:35 AM »
Here is a quick dirty explanation. If you would like me to go in more detail I will
For AutoCAD to name a few you have

Clone "Shallow Clone"      DeepClone      DeepCloneObjects         WblockClone            WblockCloneObjects


The AutoCAD commands like Copy, Mirror, Insert etc....use DeepClone.

Simple rule to be safe always use DeepClone for cloning in same drawing and WblockClone for cloning between different drawings

I get unexpected results when I use the clone method on a "visible" entity  because I believe AutoCAD checks to see if it owns any objects and if it does then it uses Deepclone

When you use DeepClone it will check if the object owns an object and if it does it will call DeepClone on that object then check if that object owns an object if so calls deepClone ............. until it reaches objects that do not own an object.
 
If I use the clone method on a block it will create a copy of the block with no entites in it.

Also deepcloning will handle translation
If copy an object with Xdata it will make sure the Xdata points to the new copy and not the original object

WblockCloneObjects is when you are copying between diffrent databases and will handle if the drawing you are copying to does not have the layer or linetype it makes a copy of that.
Deepclone is for same Database(Drawing) it make sure it points to the correct layer linetype.

There much more detail and steps involved with filing, Mapping, translating,etc...

But I will stop here so hopefully you will not figure out that I do not know what I am talking about.