Jump to content
VVA

CopyBlock - COPIES THE SELECTED BLOCK WITH A NEW NAME

Recommended Posts

VVA

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

;;; 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 ([email protected])

;;; 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

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
Lee Mac

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)
)

Share this post


Link to post
Share on other sites
Guest kruuger

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

Share this post


Link to post
Share on other sites
alanjt

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

 

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

Share this post


Link to post
Share on other sites
Lee Mac
BTW Lee, your new block will not be annotative if original was.

 

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

Share this post


Link to post
Share on other sites
alanjt
Yeah, it won't process Dynamic blocks either - "standard blocks only"...

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

Share this post


Link to post
Share on other sites
VVA
... 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)

Share this post


Link to post
Share on other sites
Lee Mac

I noticed - a nice idea all the same. :)

Share this post


Link to post
Share on other sites
alanjt

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

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...