Jump to content

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


Recommended Posts

Posted

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.

Posted

That's perfect, thank you! I legitimately have no idea how I missed that. :oops:

Posted

: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
Posted
: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?

Posted
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.

Posted

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 2
Posted

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

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

Posted

You were 13 minutes late. ;)

 

Ah, I didn't refresh the page before replying - sorry!

Posted
Ah, I didn't refresh the page before replying - sorry!

 

No worries at all and hope the OP finds these posts interesting.

  • 3 years later...
Posted
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
Posted

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

Posted

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
Posted
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.

Posted
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

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

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...