Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swapping blocks and keeping attributes

Status
Not open for further replies.

cbob

Mechanical
May 19, 2004
2
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
 
Replies continue below

Recommended for you

Use pp_SetAttsAsDottedPairs to get the original values into a list and then use pp_XchgAttsFromDottedPairs to set those values in the new titleblock.

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

&quot;Whether you think that you can, or that you can't, you are usually right &quot;
.. Henry Ford
 
BU,

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor