Jump to content

Request: Lisp command that can quick swap text between two objects


Recommended Posts

plackowski

I'm looking for a lisp command that can quick swap text between two objects, be they text, mtext, or multi-leader text. So upon running, you click on the two objects, and the text from object A moves to object B, and the text from object B moves to object A, where object A and object B can be different object types.

Link to post
Share on other sites
  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • Ish

    8

  • Jonathan Handojo

    7

  • rlx

    5

  • Grrr

    4

Top Posters In This Topic

Popular Posts

I try last year. Sir Now data not available.

May I see an example?

you mean like this ?     http://www.lee-mac.com/copytext.html

Posted Images

:lol: Heres one in "Tharwat's selecting" style:

 

(defun C:test ( / SS i o1 o2 s1 s2 )
 (cond
   ( (prompt "\nSelect two text objects to swap: ") )
   ( (not (setq SS (ssget "_:L-I"))) )
   ( (/= 2 (setq i (sslength SS))) (alert (strcat "Error: " (itoa i) " objects were selected.\n\nPlease Select EXACTLY two objects!")) ) 
   ( 
     (not 
       (vl-every 
         '(lambda (a b c / x) 
           (and 
             (vlax-property-available-p (setq x (vlax-ename->vla-object (ssname SS a))) 'TextString) 
             (set b x)
             (set c (vlax-get x 'TextString))
           )
         ) 
         '(0 1) '(o1 o2) '(s1 s2)
       )
     )
     (alert "\nOne or both of the objects doesn't support TextString property.")
   )
   ( (mapcar 'vla-put-TextString (list o1 o2) (list s2 s1)) )
 )
 (princ)
)

 

Won't work on nested objects tho.. :glare:

  • Like 1
Link to post
Share on other sites
:lol: Heres one in "Tharwat's selecting" style:

 

Hi,

I can't find my style in there. :danger::lol:

 

Why did not you add the DXF filter codes for text object along with the prompt message?

Link to post
Share on other sites
Hi,

I can't find my style in there. :danger::lol:

 

The first time I was introduced for a one-two-three-four object selection prompt with (ssget), was from one of your codes.

So with the time I started associating that technique with you, since usually most of us go for a (entsel) prompts.

Sometimes its more comfortable and faster for using. :)

 

Why did not you add the DXF filter codes for text object along with the prompt message?

 

Oh, you mean groupcode 1 ? I didn't thought of it!

I was about to use '(0 . "*TEXT*,*LEADER*,ATTDEF") but was lazy to write it (aswell think for all 0gcs that have TextString property).

Since I had to process the quite short-lengthed SS in order to obtain and reverse both string values, I didn't saw a reason to include (ssget) filters.

 

But I agree that with '(1 . "*") filter it would be better.

Link to post
Share on other sites

I will write it this way. :)

 

(defun c:txtswap (/ sel lst)
 (and (princ "\nSelect two text objects to swap: ")
      (setq sel (ssget "_:L" '((0 . "*TEXT"))))
      (or (= (sslength sel) 2)
          (alert "Must select two text objects only <!>")
      )
      (setq lst (mapcar '(lambda (x) (vlax-ename->vla-object (ssname sel x))) '(0 1)))
      (mapcar 'vla-put-textstring (reverse lst) (mapcar 'vla-get-textstring lst))
 )
 (princ)
) (vl-load-com)

  • Like 1
Link to post
Share on other sites

Looks alot simplier, :thumbsup:

BTW you could condense 1 row and skip two variables:

(mapcar 'vla-put-textstring lst (mapcar 'vla-get-textstring (reverse lst)))

Link to post
Share on other sites
Looks alot simplier, :thumbsup:

Thanks

 

BTW you could condense 1 row and skip two variables:

(mapcar 'vla-put-textstring lst (mapcar 'vla-get-textstring (reverse lst)))

You were 13 minutes late. ;)

Link to post
Share on other sites
  • 3 years later...
Ish
On 12/7/2017 at 9:11 PM, Tharwat said:

I will write it this way. :)

 

 


(defun c:txtswap (/ sel lst)
 (and (princ "\nSelect two text objects to swap: ")
      (setq sel (ssget "_:L" '((0 . "*TEXT"))))
      (or (= (sslength sel) 2)
          (alert "Must select two text objects only <!>")
      )
      (setq lst (mapcar '(lambda (x) (vlax-ename->vla-object (ssname sel x))) '(0 1)))
      (mapcar 'vla-put-textstring (reverse lst) (mapcar 'vla-get-textstring lst))
 )
 (princ)
) (vl-load-com)
 

 

Sir how we will swap text/mtext/attribute text at one time if I have

More than 2 text object left side and right side

Ex:

Left       Right

1            5

A            f

3            ty

4.           150

 

Result after copy/swap/replace 

Left 

5

 f

 ty

150

 

Note: I will select all left side text at time, not one by one.

Then right side text all at one time select.

Hope you understand sir.

 

  • Dislike 1
Link to post
Share on other sites
BIGAL

This I think was answered by PBE at Autodesk\forums or at least a method of picking text in a window  and making a list of it.

  • Like 1
Link to post
Share on other sites
Ish
1 hour ago, Jonathan Handojo said:

What do you mean "copy/swap/replace"?

Mean sir, whatever is easy for program, copy , swap, replace, send that one.

Link to post
Share on other sites
Ish
1 hour ago, BIGAL said:

This I think was answered by PBE at Autodesk\forums or at least a method of picking text in a window  and making a list of it.

Sir please send that link. Thanks

Link to post
Share on other sites
Jonathan Handojo
45 minutes ago, Ish said:

Mean sir, whatever is easy for program, copy , swap, replace, send that one.

What I don't understand is, what happens to the text on the right after the command ends?

  • Like 1
Link to post
Share on other sites
Ish
52 minutes ago, Jonathan Handojo said:

What I don't understand is, what happens to the text on the right after the command ends?

Better to make choice option sir

After command must ask choice , copy/swap/replace:

I will go with choice whatever I want for work.

Thanks 

  • Dislike 1
Link to post
Share on other sites
Jonathan Handojo
Posted (edited)
10 minutes ago, Ish said:

Better to make choice option sir

After command must ask choice , copy/swap/replace:

I will go with choice whatever I want for work.

Thanks 

No worries. Would you by any chance be interested in learning the language? It will definitely save you hassles to keep requesting for code if nobody else is keen to help out. After all, you already know how to execute AutoLISP routines. 

 

If you can attempt to write something up, post it here and see where you get stuck, we can assist you. Then the next time you want to code something up, you can actually do it yourself as opposed to posting in this forum. (Just my encouragement for you to take the first step to learning AutoLISP.)

Edited by Jonathan Handojo
  • Thanks 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...