GP_ 发表于 2022-7-6 07:42:52

Exit from (while...

Hi,
I can exit with ESC, but not very elegant.
How to exit with right click?
 
Thanks.
 
 

(defun c:Test1 (/ i )   (if (setq i (getint "\nSpecify start number: "))       (while            (entmake '((0 . "BLOCK")(2 . "TT")(70 . 0)(10 0.0 0.0 0.0)))         (entmake               (list                   (cons 0 "TEXT")                   (cons 8 (getvar "clayer"))                   (cons 7 (getvar "textstyle"))                   (cons 10 '(0.0 0.0))                   (cons 40 (getvar "textsize"))                   (cons 1 (itoa i))                )         )         (entmake '((0 . "ENDBLK")))         (prompt "\nInsertion Point:" )         (command "_-INSERT" "TT" pause "1" "1" "0")         (command "_explode" (entlast))         (setq i (1+ i))       )       (princ)   )   (princ))
 
 

(defun c:Test2 (/ i TT )   (if (setq i (getint "\nSpecify start number: "))       (while         (setq TT               (entmakex                   (list                     (cons 0 "TEXT")                     (cons 8 (getvar "clayer"))                     (cons 7 (getvar "textstyle"))                     (cons 10 '(0.0 0.0))                     (cons 40 (getvar "textsize"))                     (cons 1 (itoa i))                  )               )         )         (prompt "\nInsertion Point:" )         (command "_cutclip" TT "" "_pasteclip" pause)             (setq i (1+ i))       )       (princ)   )   (princ))

MSasu 发表于 2022-7-6 07:56:02

Not sure that how to achive that with you current code - please check the solution from this previous thread using GRREAD function.

Tharwat 发表于 2022-7-6 08:07:18

I think the grread function is the right choice in this issue
 
Try it GP
 

(defun c:Test (/ i gr p v);;;;; Tharwat 21. July. 2012 ;;;; (defun _Text ( i )   (entmakex (list (cons 0 "TEXT")         (cons 8 (getvar "clayer"))         (cons 7 (getvar "textstyle"))         (cons 10 '(0. 0. 0.))         (cons 40 (getvar "textsize"))         (cons 1 (itoa i))         )   ) ) (if (setq i (getint "\r Specify start number: "))   (progn   (setq v (_Text i))   (while   (or (eq (car (setq gr (grread t 15 0))) 5)       (eq (car gr) 3)   )    (redraw)    (entmod      (subst (cons 10 (cadr gr)) (assoc 10 (entget v)) (entget v))    )    (if (eq (car gr) 3)      (setq v (_Text (setq i (1+ i))))    )   )   )   (princ) ) (if (eq (car gr) 25)   (entdel v) ) (princ))

GP_ 发表于 2022-7-6 08:09:56

Thanks Mircea and Tharwat
 
The problem is grread does not allow insertion with OSNAP.

Tharwat 发表于 2022-7-6 08:22:53

 
Read this thread in Swamp , it's very precious and I am sure that you could handle it by your self .
 
 
http://www.theswamp.org/index.php?topic=9133.0

GP_ 发表于 2022-7-6 08:33:27

 
Wonderful
Thank you

Lee Mac 发表于 2022-7-6 08:42:00

To my knowledge, you cannot exit using right-click whilst the -insert command takes focus, since your program cannot detect the user input issued to the -insert command.
 
However, here is an alternative method to exit using Esc:
 

(defun c:test ( / c e i )   (setq c (getvar 'cmdecho))   (setvar 'cmdecho 0)   (if (setq i (getint "\nSpecify Start Number: "))       (progn         (while               (progn                   (entmake '((0 . "BLOCK") (2 . "TT") (70 . 0) (10 0.0 0.0 0.0)))                   (entmake                     (list                        '(0 . "TEXT")                           (cons 8 (getvar 'clayer))                           (cons 7 (getvar 'textstyle))                        '(10 0.0 0.0 0.0)                           (cons 40 (getvar 'textsize))                           (cons 1 (itoa i))                     )                   )                   (entmake '((0 . "ENDBLK")))                   (princ "\nInsertion Point : ")                   (setq e (entlast))                   (if                     (and                           (vl-cmdf "_.-insert" "TT" pause 1.0 1.0 0.0)                           (not (eq e (setq e (entlast))))                     )                     (progn                           (command "_.explode" e)                           (setq i (1+ i))                     )                   )               )         )         (princ "\nExit Program.") ;; To show program has not errored       )   )   (setvar 'cmdecho c)   (princ))Note that this method will not cause the program to error, as demonstrated by the message printed on exit.

GP_ 发表于 2022-7-6 08:48:24

 
If you say so I think that it can not be belied.
 
Thanks for the code.
页: [1]
查看完整版本: Exit from (while...