[LISP] Alert command and how to exit it

[LISP] Alert command and how to exit it

iBlachu
Advocate Advocate
731 Views
6 Replies
Message 1 of 7

[LISP] Alert command and how to exit it

iBlachu
Advocate
Advocate

Hi,

 

How do I know if the user presses the "OK" button or presses the ESC button after displaying the message (alert "Hi")?

 

I know you can do it on DCL but I'm interested specifically (alert).

0 Likes
732 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

Don't think so... simple alternative could be this

(acet-ui-message message [caption [type]])

Message 3 of 7

diagodose2009
Collaborator
Collaborator

You use , my fast-readkey

(Setq asm_cws12 (strcat asm_cws12 "\nEndCECOLORCIRCLE**Error** You must have CIRCLE/s inside Model.docRed\nSelect Circle/s to double:USERR1Green\nSelect Circle/s to *0.3:\ndScaleFactor(nil.)=\nrScaleFactor(nil.0.exit)=\nSelect Circle/s to scx:[YN]\nEraseTape API Test completed[Yes/No]?ERASE<ANDAND>STR\nByA:DragneAdrian2019=T469error<>Str:_.select_r_PPline-toClose(y.yes)(n.no): _.break_.pedit_y_c_xCMDACTIVECMDNAMES"))
 (setq const_systasserte nil acad__assertNo 0)
 (princ)


(Defun jc_cws12(start count / $rs)
 (setq $rs (substr asm_cws12 start count))
 (if (= $rs "") (setq $rs "eCws12Failed"))
$rs)


;Inf:Wait until press keys k
(defun dfn_getx_readkey(k574 t469 / retc kbd msg two chk lei item)
 (setq;|a67118218|;
	 retc (chr 0)
	 kbd (if (>  k574 "") k574 "")) (if (and  (/= t469 nil) (listp t469)) (foreach item t469 (princ item)) (if (=  (type t469) (read (jc_cws12 258 3))) (prompt t469) (prompt (jc_cws12 261 37)))) (setq;|a68217268|;
	 chk (if (>  (strlen kbd) 1) 0 1)) (progn (while (=  chk 0) (progn  (setq;|a000|;
	 two 0) (while (/= two 2) (setq;|a67108864|;
	 lei (grread)
	 two (car lei)) (setq;|a000|;
	 retc (strcase (chr (cadr lei)))) (setq;|a67623280|;
	 chk (if (>  kbd "") (if (wcmatch retc kbd) 1 0) 0)))))) (princ retc) 
retc)

 

Command: 'VLIDE
Command:
Command: (dfn_getx_readkey "[YN]" "\nlfEscapement[Y/N]")

lfEscapement[Y/N]Y"Y"

 

Message 4 of 7

Kent1Cooper
Consultant
Consultant

@iBlachu wrote:

....

How do I know if the user presses the "OK" button or presses the ESC button after displaying the message (alert "Hi")?

....


I'm curious....  Why would it matter?

 

If it's in the middle of some longer AutoLisp code, using ESC when an (alert) is up does not cancel the overall routine as it would under certain other circumstances, but it clears the (alert) and allows the rest of the code to continue.  So the effect, whether by the use of ESCape or Enter or picking on the OK button, is identical.

 

Do you really want to know which of those three options they used, not just which of two?  Since they could clear the (alert) with something that is neither the OK button nor ESCape, but you only check between those two, what should the "answer" to the test be if they used Enter instead?

Kent Cooper, AIA
0 Likes
Message 5 of 7

john.uhden
Mentor
Mentor

@iBlachu,

AutoCAD's alert function always returns nil.  It is intended only to grab the user's attention and give him notice that he might otherwise not see on the command line or in the text window.  It suspends a Lisp program's operation until the user hits Esc or Enter or the OK button.

I used to use a MessageBox function I picked up here years ago, but I'm not sure if it works anymore in the newer releases.  I suggest trying what @ВeekeeCZ recommended.  I need to try it myself.

John F. Uhden

Message 6 of 7

Sea-Haven
Mentor
Mentor

Like the others can write your own "Alert" dcl so the OK CANCEL doother buttons can be checked, look at help about "text" in DCL. it can have multi line "\n" 

 

a quick google

 

:row {
:text {
height = 2;
value ="This is a long\nline of text";
key ="mytxt";
}
}

 

You can make your own buttons so doother is valid.

 

Message 7 of 7

john.uhden
Mentor
Mentor

@Sea-Haven 

All true, but the alert function allows for multiple lines simply by including "\n" for a line feed, and so did the MessageBox function, so they allowed for concatenation on the fly.  Plus the MessageBox function provided for Boolean (or at least integer) values for importance icons like "Info" vs. "Warning" vs. "Critical."

Yes, you could include an image_tile, but that requires making the image per DCL limitations, which are stifling.

John F. Uhden