AutoLISP: Swap Text & Attributes

Here is a good quickie that lets you swap text objects – even Attributes that are within the same block and even attributes within different blocks. (Note: the “swapping” of attributes is actually only swapping the “value” of the and not the prompt…)

Here’s how:

  • TV <enter>
  • Select the 1st text object to be swapped
  • Select the second text object…

~enjoy

;Tip1507: TV.LSP Trade Values (c)1999, Leland Leahy

(defun c:TV (/ T1 EL1 TV1 T2 EL2 TV2)

(setvar "cmdecho" 0)

(setq

T1 (car (nentsel "\nPick first text string: "))

EL1 (entget T1)

TV1 (cdr (assoc 1 EL1))

T2 (car (nentsel "\nPick second text string: "))

EL2 (entget T2)

TV2 (cdr (assoc 1 EL2))

EL1 (subst (cons 1 TV2) (assoc 1 EL1) EL1)

EL2 (subst (cons 1 TV1) (assoc 1 EL2) EL2)

)

(entmod EL1)(entupd T1)(entmod EL2)(entupd T2)

(setvar "cmdecho" 1)

(prin1)

)
Advertisement

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in Attributes, AutoLISP, Modifying, Text. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s