Jump to content

Recommended Posts

Posted (edited)

What's the difference between common lisp and autolisp?? i have this code common lisp for reverse text:


"hello world" ----> "dlrow olleh"

the code is:

(defun C:reverse()
   (vl-list->string (reverse (vl-string->list str))
(SETQ MMT (getstring())
(REVERSE(MMT))
)

but dont work:(

Edited by hosyn
Posted

The first thing that you have used the function reverse as a name of function which is can not perform as sub-function since that it is a built-in function , secondly your function is correct but with a missing paren to be completed .

 

try .

 

(defun rev (str)
   (vl-list->string (reverse (vl-string->list str)))
)

Posted

How can that code work for reverse :

"hello world" ----> "dlrow olleh"

Posted

Why did you modify your first post after my reply ? :glare:

 

How can that code work for reverse :

"hello world" ----> "dlrow olleh"

 

Huh ؟؟؟ :huh:

Posted

dear tharwat

I try the fierst one and dont have good resault--i thoght that the first code in begun have problem:cry:.

i correct the prantess as you mentioned but unfortunately dont get result.

Posted

Hosyn, to fix your code:

(defun C:ReverseString( / )
(if (SETQ MMT (getstring "\nInput string to be reversed: "))
 (print (vl-list->string (reverse (vl-string->list MMT))))
)
(princ)
)

Posted

Alternatively, using only Vanilla AutoLISP:

(defun reversestring ( str / lst )
   (repeat (strlen str)
       (setq lst (cons (substr str 1 1) lst)
             str (substr str 2)
       )
   )
   (apply 'strcat lst)
)

_$ (reversestring "Hello World!")
"!dlroW olleH"

Posted

Stange that the code in VisualLisp has more characters (therefore longer) than...

 

(defun C:ReverseString( / )
(if (SETQ MMT (getstring "\nInput string to be reversed: "))
 (print (vl-list->string (reverse (vl-string->list MMT))))
)
(princ)
)

 

...the vanilla AutoLisp code.

(defun reversestring ( str / lst )
   (repeat (strlen str) 
      (setq lst (cons (substr str 1 1) lst) 
         str (substr str 2) 
      )
   ) 
   (apply 'strcat lst)
)

Posted

LibertyOne, the VLISP code you used in comparison contains in fact extra statements to allow for testing. Instead should check against this:

(defun ReverseString( str / )
(vl-list->string (reverse (vl-string->list str)))
)

Posted

How about using system variable Mirrtext set to 1. :)

Posted

Or,

(defun c:revtxt ( / i s )
   (if (setq s (ssget "_:L" '((0 . "TEXT") (-4 . "<NOT") (-4 . "&=") (71 . 2) (-4 . "NOT>"))))
       (repeat (setq i (sslength s))
           (vla-put-backward (vlax-ename->vla-object (ssname s (setq i (1- i)))) :vlax-true)
       )
   )
   (princ)
)
(vl-load-com) (princ)

Posted
How about using system variable Mirrtext set to 1. :)

Dong95, I believe that the OP was looking to programatically reverse a string stored into a variable (that it, invert the order of its characters), not to show in mirror a text entity in editor; example:

"MIRRTEXT" --> "TXETRRIM"

  • 6 months later...
Posted

Can you all make a lisp with select all txt mtxt and reverse value on that in a drawing?

Posted

Cuasuavdd, a routine to batch reverse all TEXT type labels in the drawing using one of the above proposed solutions will be quite easy. However, for MTEXT will be a quite laborious task since for those the formatting is retained as control strings along text value, so will need to be skipped at reverse.

 

Also, welcome to the Forum!

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