Jump to content

Recommended Posts

Posted

;;;-------------------------------------------------------------------------------------------------------------------------------

;;; CopyBlock - ROUTINE TO COPIES THE SELECTED BLOCK WITH A NEW NAME

;;; Work (i HOPE) with dynamic block

;;; Created by Vladimir Azarko (VVA) 2010-06-02 (azarko@yandex.ru)

;;; Credits to Tony Tanzillo, Joe Burke and Vishal Gonsalves for sharing their lisp copyblock.lsp

;;; http://discussion1.autodesk.com/forums/thread.jspa?messageID=6182594

;;; http://discussion.autodesk.com/forums/thread.jspa?threadID=767010

;;; posted http://forum.dwg.ru/showthread.php?t=36419

;;;-------------------------------------------------------------------------------------------------------------------------------

Any suggestion is welcomed

CopyBlock-VVA.lsp

Posted

Interesting approach Vladimir, I must say. I wouldn't have thought to create a temporary document to house the block definition so that you could change its name. I probably would have created a new Block Definition with the new name, and then just used CopyObjects to copy everything contained in the old definition into the new one... but nice code all the same.

 

Lee

Posted

Perhaps in Vanilla it might look like this - (standard blocks only of course):

 

(defun CopyBlock ( old new / tdef )
 ;; © Lee Mac  ~  07.06.10
 (if (setq tdef (tblsearch "BLOCK" old))
   (progn
     (entmake (subst (cons 2 new) (assoc 2 tdef) tdef))
     (mapcar 'entmake (mapcar 'entget (GetObj (tblobjname "BLOCK" old))))
     (entmake (list (cons 0 "ENDBLK") (cons 8 "0")))
   )
 )
 new
)

(defun GetObj ( e )
 (if (setq e (entnext e)) (cons e (GetObj e)))
)

(defun c:test ( / ent old new )
 ;; © Lee Mac  ~  07.06.10
 (if (and (setq ent (ssget "_+.:S:E:L" '((0 . "INSERT"))))
          (setq ent (entget (ssname ent 0)))
       (progn
         (while
           (progn            
             (setq new
               (getstring t
                 (strcat "\nNew Block Name <Copy of "(setq old (cdr (assoc 2 ent))) ">: ")
               )
             )
             (cond ( (eq "" new) (setq new (strcat "Copy of " old)) nil)
                   ( (or (not (snvalid new)) (tblsearch "BLOCK" new))
                     (princ "\n** Block Name Not Valid **")
                   )
             )
           )
         )
         new
       )
     )
   (if (CopyBlock old new)
     (entmod (subst (cons 2 new) (assoc 2 ent) ent))
     (princ "\n** Block Copy Failed **")
   )
 )
 (princ)
)

Guest kruuger
Posted

please see attachment how the amateur (Me) play with this.

 

i like your idea with DCL.

i think that only one thing is missing. Check to see if block is an Xref.

 

kruuger

Block Clone.lsp

Posted

Very cool Vladimir! I'm sure it will be useful to many.

 

BTW Lee, your new block will not be annotative if original was.

Posted
BTW Lee, your new block will not be annotative if original was.

 

Yeah, it won't process Dynamic blocks either - "standard blocks only"...

Posted
Yeah, it won't process Dynamic blocks either - "standard blocks only"...

Just putting the information out there for the world.:wink:

Posted
... to create a temporary document to house the block definition so that you could change its name. ...

Lee

Yeah, it won't process Dynamic blocks either - "standard blocks only"...

Because of the dynamic blocks I did. This idea, I spied a Vishal Gonsalves (see the references in # 1)

  • 4 months later...
Posted

Had a use for this today and just wanted to say thanks; saved me a little legwork.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...