Swapping blocks and keeping attributes
Swapping blocks and keeping attributes
(OP)
We're trying to update our titleblocks on all of our drawings, but I want this to be an automated process in carrying over the existing attributes from the old block to the new. I understand that the fields in both blocks need to be the same, but is there a lisp routine (or even an existing command) that I can run to replace the old block with the new & maintain all attribute info?
Any help would be appreciated.
Chris Bobrowski
Any help would be appreciated.
Chris Bobrowski





RE: Swapping blocks and keeping attributes
;------------------------------------------------------------------------------
;pp_SetAttsAsDottedPairs:
;
;Arguments: <Entity name: 400e1978>
;Returns: (("DATE" . "20020304")("TITLE" . "some drawing"))
;Dependencies: pp_GetEntVal
;------------------------------------------------------------------------------
(defun pp_SetAttsAsDottedPairs (BLKWATTS / ALIST ATTAG ATTTXT MORE TBNEXT
TITLENT)
(setq MORE T
TITLENT (entnext BLKWATTS))
(while MORE
(setq TBNEXT (entget TITLENT))
(cond ((= (pp_EntVal TBNEXT 0) "ATTRIB")
(setq ATTAG (pp_GetEntVal TBNEXT 2)
ATTTXT (pp_GetEntVal TBNEXT 1)
ALIST (append (list (cons ATTAG ATTTXT))ALIST)
TITLENT (entnext TITLENT))
) ;cond1
((= (pp_GetEntVal TBNEXT 0) "SEQEND") (setq MORE NIL))
(t (setq TITLEENT (entnext TITLEENT)))
) ;cond
) ;while
ALIST
) ;defun
;------------------------------------------------------------------------------
;pp_XchgAttsFromDottedPairs: Looks for matching tags and sets string in block
;
;Arguments: <Entity name: 400e1978> (("DATE" . "20020304")("TITLE" . "drwng"))
;Returns:
;Dependencies: pp_GetEntVal, pp_AttMod
;------------------------------------------------------------------------------
(defun pp_XchgAttsFromDottedPairs (BLKWATTS ALIST / ATTAG ATTTXT INLIST
MORE TBNEXT TITLENT)
(setq MORE T
TITLENT (entnext BLKWATTS))
(while MORE
(setq TBNEXT (entget TITLENT))
(cond ((= (pp_GetEntVal TBNEXT 0) "ATTRIB")
(setq ATTAG (pp_GetEntVal TBNEXT 2)
ATTTXT (pp_GetEntVal TBNEXT 1)
TITLENT (entnext TITLENT))
(if (setq INLIST (assoc ATTAG ALIST)) ;make sure tag exists
(pp_AttMod TBNEXT (cdr INLIST))
) ;if
) ;cond1
((= (pp_GetEntVal TBNEXT 0) "SEQEND") (setq MORE NIL))
(t (setq TITLEENT (entnext TITLEENT)))
) ;cond
) ;while
(command "REGEN") ;For on screen updating
) ;defun
;------------------------------------------------------------------------------
;pp_AttMod
;------------------------------------------------------------------------------
(defun pp_AttMod (E ATT)
(setq E (subst (cons 1 ATT) (assoc 1 E) E))
(entmod E)
(entupd E)
)
;------------------------------------------------------------------------------
;pp_GetEntVal
;------------------------------------------------------------------------------
(defun pp_GetEntVal (E NUM)
(cdr (assoc NUM E))
)
;------------------------------------------------------------------------------
;pp_SetEntVal
;------------------------------------------------------------------------------
(defun pp_SetEntVal (E TAG NEWVAL)
(setq E (subst (cons TAG NEWVAL) (assoc TAG E) E))
(entmod E)
(entupd E)
)
"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford
RE: Swapping blocks and keeping attributes
Thank you for this, however I am a complete newbie when it comes to LISP (outside of dragging the lisp function to the AutoCAD window!) :) How would I be able to set this up such that I can pick the first block, then pick the second block to add the attribute data? Also, from what little I know, where are 'BLKWATTS' & 'ALIST ' defined?
Again, any help (and patience) would be appreciated.
C