Swapping blocks using LSP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I attached a LSP that I run to convert older (out of date) blocks to my new blocks with all my updated information. This LSP only works if all your attributes match, otherwise if they don't, it throws a code which is an awesome feature. When you run this, it asked you to select the "base" block and then it asked you to select the new block you want all the information (from the old block to the new block) you want to use. Can this LSP be changed so that the function does this:
When you prompt "MTB" via the command, it will automatically select a particular block you have chosen at a specific location on your computer and run the rest of the code as normal (meaning, select the "base" block and replace with the new block)? or even better, automatically erase the old block after you have selected it and the new block would be placed directly at the same place the old block use to reside at.
;THIS LSP WILL CONVERT AN OLD BLOCK TO WHATEVER NEW BLOCK YOU WANT. THE ATTRIBUTE "TAGS" NEED TO MATCH FOR THIS TO WORK. INSERT THE MTB.LSP AND ENTER "MTB" INTO AUTOCAD COMMAND LINE TO ACTIVATE IT.
(princ "\nType MTB to Run")
(defun C:MTB (/)
(setq baselist (list))
(setq ename (car (entsel "\nSelect Base Block:")))
(while (= ename nil)
(princ "\nNothing Picked")
(setq ename (car (entsel "\nSelect Base Block:")))
);end while
(setq ename1 (car (entsel "\nSelect Title Block To Apply Changes:")))
(while (= ename1 nil)
(princ "\nNothing Picked")
(setq ename1 (car (entsel "\nSelect Block To Apply Changes:")))
);end while
(setq ename (entnext ename))
(setq elist (entget ename)) ;the entity list of the base border
(setq etype (cdr (assoc 0 elist))) ;should be attrib
(while (= etype "ATTRIB") ;puts all the attribute in a list
(setq tag (cdr (assoc 2 elist))) ;the attribute tag
(setq val (cdr (assoc 1 elist)));the attribute value
(setq baselist (append (list (list tag val)) baselist));put the attribute in list
(setq ename (entnext ename)) ;move onto the next attribute
(setq elist (entget ename))
(setq etype (cdr (assoc 0 elist)))
);end while
(setq ename1 (entnext ename1)) ;get the next entity, should be "ATTRIB"
(setq elist1 (entget ename1)) ;the entity list of the border
(setq etype1 (cdr (assoc 0 elist1))) ;should be attrib
(while (= etype1 "ATTRIB")
(setq attval nil)
(setq tag (cdr (assoc 2 elist1)));the attribute tag
(foreach item baselist
(if (= tag (nth 0 item))
(progn
(setq attval (nth 1 item))
);end then
(progn);else do nothing go to next in list till tag matches
);end if
);end foreach
(if (/= attval nil)
(progn (setq elist1 (subst (cons 1 attval) (assoc 1 elist1) elist1))
(entmod elist1));end then
(progn);end else
);end if
(setq ename1 (entnext ename1)) ;move onto the next attribute
(setq elist1 (entget ename1))
(setq etype1 (cdr (assoc 0 elist1)))
);end while
(command "REGEN")
);end defun
(princ)