Jump to content

Flip text - lisp


jamestamayo

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

InverseText.gif

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 6 years later...

For some reason, the generous code submission has not effect on the TEXT or MTEXT in a file with the MIRRTEXT setting both as 1 or 0 (zero).

 

I renamed Test to Fliptxt.lsp that appears to be run successfully.

 

 

Link to comment
Share on other sites

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