plackowski Posted December 7, 2017 Posted December 7, 2017 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. Quote
rlx Posted December 7, 2017 Posted December 7, 2017 you mean like this ? http://www.lee-mac.com/copytext.html 1 Quote
plackowski Posted December 7, 2017 Author Posted December 7, 2017 That's perfect, thank you! I legitimately have no idea how I missed that. Quote
Grrr Posted December 7, 2017 Posted December 7, 2017 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.. 1 Quote
Tharwat Posted December 7, 2017 Posted December 7, 2017 Heres one in "Tharwat's selecting" style: Hi, I can't find my style in there. Why did not you add the DXF filter codes for text object along with the prompt message? Quote
Grrr Posted December 7, 2017 Posted December 7, 2017 Hi,I can't find my style in there. 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. Quote
Tharwat Posted December 7, 2017 Posted December 7, 2017 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) 2 Quote
Grrr Posted December 7, 2017 Posted December 7, 2017 Looks alot simplier, BTW you could condense 1 row and skip two variables: (mapcar 'vla-put-textstring lst (mapcar 'vla-get-textstring (reverse lst))) Quote
Tharwat Posted December 7, 2017 Posted December 7, 2017 Looks alot simplier, 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. Quote
Grrr Posted December 7, 2017 Posted December 7, 2017 You were 13 minutes late. Ah, I didn't refresh the page before replying - sorry! Quote
Tharwat Posted December 7, 2017 Posted December 7, 2017 Ah, I didn't refresh the page before replying - sorry! No worries at all and hope the OP finds these posts interesting. Quote
Ish Posted May 2, 2021 Posted May 2, 2021 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. 1 Quote
BIGAL Posted May 3, 2021 Posted May 3, 2021 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. 1 Quote
Ish Posted May 3, 2021 Posted May 3, 2021 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. Quote
Ish Posted May 3, 2021 Posted May 3, 2021 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 Quote
Jonathan Handojo Posted May 3, 2021 Posted May 3, 2021 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? 1 Quote
Ish Posted May 3, 2021 Posted May 3, 2021 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 1 Quote
Jonathan Handojo Posted May 3, 2021 Posted May 3, 2021 (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 May 3, 2021 by Jonathan Handojo 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.