Jump to content

Block Swap AutoLisp


Recommended Posts

My version is similar, except you select one of the original blocks, then the new block, then create a selection box around the blocks you want to replace.


(defun c:replace ( / old-block new-block block-sel lcv block)
(setq old-block (entget (car (entsel "\nSelect the old block: ")))
      new-block (entget (car (entsel "\nSelect the new block: ")))
      lcv (princ "\nSelect blocks to be replaced: ")
      block-sel (ssget (list (assoc 2 old-block)))
      lcv 0)
(while (< lcv (sslength block-sel))
 (setq block (entget (ssname block-sel lcv)))
 (entmod (subst (assoc 2 new-block) (assoc 2 old-block) block))
 (setq lcv (+ 1 lcv))

Link to comment
Share on other sites

Thanks Eric

Have a look at attached it belongs to Aleksandr Smirnov

Lovely routine BUT....!!! when you swop/replace Blocks he REMOVES the Attributes of the Swopped Blocks which is a pity. Wish he would amend to retain attribute info as selected blocks are swopped over to a new block name..


Cheers john


Link to comment
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.

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