Jonathan Handojo Posted May 3, 2021 Posted May 3, 2021 5 hours ago, Ish said: I appreciate that, Sir I try many time but fail. May I see an example? 2 Quote
Jonathan Handojo Posted May 3, 2021 Posted May 3, 2021 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) ) ) ) 1 Quote
Lee Mac Posted May 3, 2021 Posted May 3, 2021 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))) Quote
Jonathan Handojo Posted May 3, 2021 Posted May 3, 2021 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. Quote
Lee Mac Posted May 3, 2021 Posted May 3, 2021 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. Quote
Ish Posted May 4, 2021 Posted May 4, 2021 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 1 Quote
rlx Posted May 4, 2021 Posted May 4, 2021 @Jonathan Handojo you should know by now that no good deed goes unpun(Ish)ed 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 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.lsp 1 Quote
Jonathan Handojo Posted May 4, 2021 Posted May 4, 2021 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.... Quote
rlx Posted May 4, 2021 Posted May 4, 2021 (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 May 4, 2021 by rlx Quote
Ish Posted May 5, 2021 Posted May 5, 2021 16 hours ago, rlx said: @Jonathan Handojo you should know by now that no good deed goes unpun(Ish)ed 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 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.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. Quote
rlx Posted May 5, 2021 Posted May 5, 2021 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 1 Quote
faizur Posted March 7, 2023 Posted March 7, 2023 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" Quote
Tharwat Posted March 7, 2023 Posted March 7, 2023 1 hour ago, faizur said: Working perfectly "Jazaak Allaahu Khayran" You're welcome. 1 Quote
Recommended Posts
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.