Jump to content

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


Recommended Posts

Posted

I appreciate that,

Sir I try many time but fail.

 

  • Dislike 1
Posted
5 hours ago, Ish said:

I appreciate that,

Sir I try many time but fail.

 

May I see an example?

  • Like 2
Posted

I try last year. Sir

Now data not available.

  • Dislike 1
  • Funny 1
Posted

Oh boy...

 

Here's a starting point for you (even though this is probably already out there somewhere):

;; SwapReplaceText
;; Swaps or replaces one text entity with another
;; txt1, txt2 [vla-object] - the text/mtext VLA-Object
;; flg [int] - the integer to flag the operation:
;;	1 - Swaps the two texts together
;;	2 - Replaces txt1 with the contents of txt2 and vice versa

(defun SwapReplaceText (txt1 txt2 flg / t1 t2)
    (cond
	((= flg 1)
	 (mapcar '(lambda (a b) (set a (vla-get-TextString b))) '(t1 t2) (list txt1 txt2))
	 (mapcar '(lambda (a b) (vla-put-TextString a b)) (list txt1 txt2) (list t2 t1))
	 )
	((= flg 2)
	 (vla-put-TextString txt1 (vla-get-TextString txt2))
	 (vla-Delete txt2)
	 )
	)
    )

 

  • Like 1
Posted

FWIW, you could avoid the slack variables t1 & t2 by using:

(mapcar 'vla-put-textstring (list txt2 txt1) (mapcar 'vla-get-textstring (list txt1 txt2)))

 

Posted
7 minutes ago, Lee Mac said:

FWIW, you could avoid the slack variables t1 & t2 by using:


(mapcar 'vla-put-textstring (list txt2 txt1) (mapcar 'vla-get-textstring (list txt1 txt2)))

 

 

Hmm... that's funny. I didn't test the above, but I was confident it would work fine. I thought if I had done it your way, then (vla-get-textstring txt2) would've returned the updated textstring resulting from the first evaluation, hence I used some slack variabled.

 

Sometimes I also questioned myself when I do (mapcar 'set '(a b) (list b a)) and it worked fine, even though it's the equivalent to (list (set 'a b) (set 'b a)), but I guess mapcar has its secrets that needs a bit of unraveling.

Posted
6 minutes ago, Jonathan Handojo said:

Hmm... that's funny. I didn't test the above, but I was confident it would work fine. I thought if I had done it your way, then (vla-get-textstring txt2) would've returned the updated textstring resulting from the first evaluation, hence I used some slack variabled.

 

Sometimes I also questioned myself when I do (mapcar 'set '(a b) (list b a)) and it worked fine, even though it's the equivalent to (list (set 'a b) (set 'b a)), but I guess mapcar has its secrets that needs a bit of unraveling.

 

Whilst semantically (mapcar 'set '(a b) (list b a)) is the equivalent of (list (set 'a b) (set 'b a)), in practice, since mapcar is not a special form (like and/or/etc.), short-circuit evaluation does not apply and all arguments are evaluated prior to the operations performed by the mapcar function, hence (list b a) will be evaluated prior to any evaluation of the set function.

Posted
12 hours ago, Jonathan Handojo said:

Oh boy...

 

Here's a starting point for you (even though this is probably already out there somewhere):


;; SwapReplaceText
;; Swaps or replaces one text entity with another
;; txt1, txt2 [vla-object] - the text/mtext VLA-Object
;; flg [int] - the integer to flag the operation:
;;	1 - Swaps the two texts together
;;	2 - Replaces txt1 with the contents of txt2 and vice versa

(defun SwapReplaceText (txt1 txt2 flg / t1 t2)
    (cond
	((= flg 1)
	 (mapcar '(lambda (a b) (set a (vla-get-TextString b))) '(t1 t2) (list txt1 txt2))
	 (mapcar '(lambda (a b) (vla-put-TextString a b)) (list txt1 txt2) (list t2 t1))
	 )
	((= flg 2)
	 (vla-put-TextString txt1 (vla-get-TextString txt2))
	 (vla-Delete txt2)
	 )
	)
    )

 

Oh sir,

Difficult for me to complete.

I will be very thankful to you, if you provide full code for multiple text swapping at a time.

Thanks

  • Dislike 1
Posted

@Jonathan Handojo you should know by now that no good deed goes unpun(Ish)ed :rofl:

 

anyways , @Ish , this is one of my oldtimers but still in use today by me anyway. If it works:  fine , if it doesn't : tough....

 

use (load "vt") , type vt to start command and press spacebar for plugin menu. Row2row is copy and Swap , well if I have to tell you you're an :censored:

routine uses Grread function so you can't exit program the normal way , either use escape of press space to enter plugin menu again and click cancel.

 

Have posted this many years ago so look for VT on this site for manual. All the revision and titleblock stuff is company specific so these parts wont work and I'm not gonna change this for one person.

🐉

 

 

VT.jpg.c8997239c2eee754e6f03a0691cfdb24.jpgvt.lsp

  • Thanks 1
Posted
4 hours ago, rlx said:

@Jonathan Handojo you should know by now that no good deed goes unpun(Ish)ed

 

Well, I was trying to be encouraging. Now I'm kind of punishing him back....

Posted (edited)

I totally understand what you mean Jonathan , the principle of seeders & leechers / shoppers has been discussed more than once on this forum and every now and again it resurfaces. When you have kids and they ask if you can please help with their homework you first want them to have put in some effort of their own instead of them giving it to you and say 'make my homework (grand)pa , I have no time because I rather play with the other children' . And of course most of us don't have an extraterrestrial brain like master Lee but I rather die trying (to solve a problem) than giving up at the very first obstacle (french lessons excepted because after one lesson at mid school I alreay knew this was not for me haha)

Edited by rlx
Posted
16 hours ago, rlx said:

@Jonathan Handojo you should know by now that no good deed goes unpun(Ish)ed :rofl:

 

anyways , @Ish , this is one of my oldtimers but still in use today by me anyway. If it works:  fine , if it doesn't : tough....

 

use (load "vt") , type vt to start command and press spacebar for plugin menu. Row2row is copy and Swap , well if I have to tell you you're an :censored:

routine uses Grread function so you can't exit program the normal way , either use escape of press space to enter plugin menu again and click cancel.

 

Have posted this many years ago so look for VT on this site for manual. All the revision and titleblock stuff is company specific so these parts wont work and I'm not gonna change this for one person.

🐉

 

 

VT.jpg.c8997239c2eee754e6f03a0691cfdb24.jpg vt.lsp 241 kB · 3 downloads

Oh, @rlx this the one I was looking for.

Thanks thanks very much, your program is wonderful , again thanks for kind support and excellent program.

Posted

its not perfect nor will it ever win a price for prettiest programming style but it works well for me and my colleagues. Have made some parts a little bit more modern but found out that old school programming (vanilla) sometimes is much faster than vla- commands so decided to stick with vanilla on this one. It is mainly used for text en attributes and sometimes it tolerates mtext. But hey , it's allmost 25 years old and still one of my most valued appies by my colleagues so it must be doing something right hey 😁

 

🐉

  • Like 1
  • 1 year later...
Posted
On 12/7/2017 at 9:41 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)
 

 

Working perfectly "Jazaak Allaahu Khayran"

Posted
1 hour ago, faizur said:

Working perfectly "Jazaak Allaahu Khayran"

You're welcome.

  • Like 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...