jamestamayo 发表于 2022-7-5 15:37:23

Flip text - lisp

Hi, today is my first day in this group.
I would like to thank the admin of this group for accepting my registration.
 
I join here to learn things, techniques, etc. and sometimes I encountered problems that I can't find solution by browsing on the internet. I'm sure you can help & teach me.
 
First thing I need your help is about flipping/mirroring the text content. I usually use this in wiring connection. The format is SOURCE/DESTINATION. So, for example, my wire label on one end is TB1.1/TB9.8. I need to label the other end with T9.8/TB1.1. As you can see, it mirrors or flips the value after the / symbol.
 
I'm using Lee Mac's CopySwapTextV1-7.lsp that copy or swap the texts but I don't know how to modify it so I can use it for my purpose.
 
I really appreciate your help.
Thanks

SLW210 发表于 2022-7-5 15:49:36

I moved your thread to the AutoLISP, Visual LISP & DCL Forum, please ask questions in the most appropriate forum.

Aftertouch 发表于 2022-7-5 16:04:32

Welcome to this forum!
Im sure you can learn alot around here!
 
About your question, here is a very simple code:
I dont have time for a full code, but this may get someone started.

(setq test "Hello/Goodbye")(setq result (strcat (substr test (+ 2 (vl-string-position (ascii "/") test))) "/" (substr test 1 (vl-string-position (ascii "/") test))))"Goodbye/Hello"
 
Where the format is flipped.

Grrr 发表于 2022-7-5 16:16:25

Hi,

(defun C:test ( / f )(setq f   '( ( c s / L cL )   (cond      ( (not (eq 'STR (type s))) nil)       (         (if (member c (setq cL (vl-string->list s)))         (apply 'strcat            (apply 'append               (mapcar                  ''( (x / tmp)                   (cond                     ( (not x) (if L (list (vl-list->string L))) )                     ( (= c x) (setq tmp L) (setq L nil) (list (vl-list->string (append tmp (list c)))) )                     ( (setq L (cons x L)) nil )                   )               )               (reverse (cons nil cL))               )             )         )         s         )       )   )   ) )(princ "\nSelect texts to inverse: ") (foreach x   ('((/ SS) (if (setq SS (ssget "_:L-I" '((0 . "TEXT")))) (vl-remove-if-not ''((x) (eq 'ENAME (type x))) (apply 'append (ssnamex SS))))))   ('(( enx / g ) (setq g (assoc 1 enx)) (entmod (subst (cons 1 (f 47 (cdr g))) g enx))) (entget x)) ) (princ))
 

jamestamayo 发表于 2022-7-5 16:26:03

thank you very much Aftertouch & Grrr... it works perfectly.
 
I replace "TEXT" with "MTEXT" so it will work with MTEXT too but it doesn't work with TEXT.
How to make it work for both TEXT and MTEXT?
 
thanks a lot...

ronjonp 发表于 2022-7-5 16:35:52

"MTEXT,TEXT" .. You might run into issues with mtext formatting though.

jamestamayo 发表于 2022-7-5 16:39:36

thanks ronjonp... it helps a lot...
页: [1]
查看完整版本: Flip text - lisp