Visual lisp code

Visual lisp code

michalcapek4
Contributor Contributor
999 Views
3 Replies
Message 1 of 4

Visual lisp code

michalcapek4
Contributor
Contributor

hi i have a visual lisp code that manages to swap between texts, i didnt create this code but it works:

 

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

)

 

I have however mtexts and mleaders and i need to swap texts between them , this lisp code works for mtexts only. Anybody knows how to alter this code in order to achieve swapping text between mtext and mleader? 

 

 

0 Likes
Accepted solutions (1)
1,000 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

The text content of MultiLeaders is held in the 304-code entry in entity data, not the 1-code entry as in Mtext and Text and Dimension override content and Attributes.

 

This decides which of those numbers to use for a given entity type, and feeds that in accordingly in place of the 1's in the original [minimally tested]:

 

(defun c:TV (/ T1 EL1 dxf1 TV1 T2 EL2 dxf2 TV2)
  (setq
    T1 (car (nentsel "\nPick first text string: "))
    EL1 (entget T1)
    dxf1 (if (wcmatch (cdr (assoc 0 EL1)) "*TEXT") 1 304)
    TV1 (cdr (assoc dxf1 EL1))
    T2 (car (nentsel "\nPick second text string: "))
    EL2 (entget T2)
    dxf2 (if (wcmatch (cdr (assoc 0 EL2)) "*TEXT") 1 304)
    TV2 (cdr (assoc dxf2 EL2))
    EL1 (subst (cons dxf1 TV2) (assoc dxf1 EL1) EL1)
    EL2 (subst (cons dxf2 TV1) (assoc dxf2 EL2) EL2)
  )
  (entmod EL1) (entupd T1) (entmod EL2) (entupd T2)
  (prin1)
)

It also works with regular Text, as well as Mtext & MultiLeaders, and though I didn't test it on things like Dimension override, it should work on other things with 1-code entries for text content.

 

I removed the CMDECHO-related lines, because they don't do anything for you when no commands are beng used.  It could be improved in some other ways, such as to prevent selection of invalid object types, highlight the first one you select so you can see that you got it, etc., as well as the usual *error* handling and so on.

Kent Cooper, AIA
Message 3 of 4

michalcapek4
Contributor
Contributor

WOW! thanks so much and speedy reply cheers!

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

You're welcome, but I misspoke a little....  As written, it won't work on other 1-code-text-content things like Dimensions with override [if you have any reason to use it with such things], until you add such other entity type(s) to the (wcmatch) pattern string.  Or, do as BeeKeeCZ had it before withdrawing the post, testing for MLEADER-ness instead [since that's the one kind that uses the 304 code for its text content], and reverse the 1 and 304 'then' and 'else' arguments:

 

....
  dxf1 (if (wcmatch (cdr (assoc 0 EL1)) "MULTILEADER") 304 1)
....

and similarly for dxf2.

 

Kent Cooper, AIA
0 Likes