×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Swapping blocks and keeping attributes

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

RE: Swapping blocks and keeping attributes

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

"Whether you think that you can, or that you can't, you are usually right "
.. Henry Ford

RE: Swapping blocks and keeping attributes

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources