russell84 Posted April 28, 2008 Share Posted April 28, 2008 Anyone know the code in lisp to create a warning message that has yes no buttons? and does one function if yes and another if no??? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted April 28, 2008 Share Posted April 28, 2008 Anyone know the code in lisp to create a warning message that has yes no buttons? and does one function if yes and another if no??? Thanks in advance If you are a casual customiser, have a look at DosLib http://download.mcneel.com/download.asp?id=doslib DOSLib, is a library of AutoLISP/Visual Lisp-callable functions that provides a variety of Windows operating system capabilities to AutoCAD. Written as an AutoCAD ObjectARX application, DOSLib extends the AutoLISP and Visual LISP programming languages by providing the following functionality: DOSLib, is a library of AutoLISP/Visual Lisp-callable functions that provides a variety of Windows operating system capabilities to AutoCAD. Written as an AutoCAD ObjectARX application, DOSLib extends the AutoLISP and Visual LISP programming languages by providing the following functionality: (dos_msgbox text title button icon [duration]) see the help file for sample code ... If you want to roll your own, perhaps look as OpenDCL http://opendcl.com/wordpress/ https://sourceforge.net/project/showfiles.php?group_id=187950 ... or you could use standard DCL , I recall seeing several examples of YesNo type DCL dialogs around. Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted April 28, 2008 Share Posted April 28, 2008 .. or if you have express tools loaded, try something like this .. (SETQ reply (ACET-UI-MESSAGE "Choose dude " "Russells Dialog" (+ Acet:YESNOCANCEL Acet:ICONWARNING) ) ) ;; Yes = 6 ;; No = 7 ;; Cancel = 2 (IF (= reply 6) (PROGN (ALERT "Yep") ;; ;; More Yes Mojo ) ;; else (PROGN (ALERT "Nope") ;; ;; More no mojo ) ) Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted April 28, 2008 Share Posted April 28, 2008 or this may suit you better (SETQ reply (ACET-UI-MESSAGE "Choose dude " "Russells Dialog" (+ Acet:YESNO Acet:ICONQuestion) ) ) Quote Link to comment Share on other sites More sharing options...
russell84 Posted April 28, 2008 Author Share Posted April 28, 2008 ahh wow - well to respond appropriately - SWEET DUDE!!! hahaa thats really neat - thanks for that - I know how to do it within DCL but i didnt want to go through the effort of loading dcl and creating another associated file for this lisp. Thanks again - and yes i have express loaded Quote Link to comment Share on other sites More sharing options...
CAB Posted April 28, 2008 Share Posted April 28, 2008 This will create the DCL for you. ;; YesNo.lsp CAB 04.260.2008 ;; Creates a DCL file on the fly for Yes/No Prompt ;; Arguments: ;; BoxTitle = Dialog Box Title ;; Question = Question to be displayed ;; Sample Call (YesNo " My Yes No" "Do you like creating programs in AutoLISP?") ;; Returns "Yes" or "No" from user or nil if the DCL failed (defun YesNo (BoxTitle Question / Dcl_Id% Result acadfn fn fid) (if (and (or (setq fn (findfile "YesNo.dcl")) (setq acadfn (findfile "ACAD.PAT") fn (strcat (substr acadfn 1 (- (strlen acadfn) ) "YesNo.dcl"))) (setq fid (open fn "w")) ) ;; create dcl file in same directory as ACAD.PAT (progn (foreach x (list "YesNo : dialog { key = \"Title\";" " spacer;" (strcat " : text { key = \"Question\" ; width = " (itoa (+ (strlen Question) 4)) " ; alignment = centered; }") " spacer;" " : row { fixed_width = true; alignment = centered;" " : button { key = \"Yes\"; label = \"&Yes\"; is_default = true;}" " : button { key = \"No\"; label = \"&No\"; is_cancel = true;}" " }" "}" ) (princ x fid) (write-line "" fid) ) (close fid) ) ) (cond ((setq Dcl_Id% (load_dialog fn)) (new_dialog "YesNo" Dcl_Id%) (set_tile "Title" BoxTitle) (set_tile "Question" Question) (action_tile "Yes" "(done_dialog 1)") (action_tile "No" "(done_dialog 0)") (setq Result (start_dialog)) (unload_dialog Dcl_Id%) ; Unload Dialog (if (and Result (= Result 1)) "Yes" "No") ) (t nil) ) ) Quote Link to comment Share on other sites More sharing options...
russell84 Posted April 28, 2008 Author Share Posted April 28, 2008 you can create a dialog box in DCL using lisp. wow i did not know that - thanks CAB Thats great because then i don't have to rely on having 2 file for the lisp. i'LL END UP USING THAT A LOT Thank you Quote Link to comment Share on other sites More sharing options...
fuccaro Posted April 29, 2008 Share Posted April 29, 2008 This will create the DCL for you.;; YesNo.lsp CAB 04.260.2008 ;; Creates a DCL file on the fly for Yes/No Prompt ......... CAB What's your local stardate? Never mind! Jealousy makes me evil Quote Link to comment Share on other sites More sharing options...
CAB Posted April 29, 2008 Share Posted April 29, 2008 You would think looking at the keys while you type would eliminate those mistakes. Wrong Quote Link to comment Share on other sites More sharing options...
wishbonesr Posted August 31, 2012 Share Posted August 31, 2012 I don't generally write a loop for this, but here's a formula I use after designing a dialog in vlide. I copy the text into excel. Note: if I use tabs in the dcl formatting, I must import the text and choose to ignore the tabs as a delimeter. Then in the B column, or where-ever... ="(write-line """ & REPT("\t",LEN(A1)-LEN(SUBSTITUTE(A1, CHAR(9),""))) & SUBSTITUTE(SUBSTITUTE(A1, CHAR(9),""),"""", "\""") & """ dclf)" Copy the formula to the remaining lines and copy the output back to vlide in a function. dclf is the dcl file, and below exmple uses var fn in CAB's example. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 2, 2012 Share Posted September 2, 2012 I will post soon a getval.dcl not at work, you supply the title, width of box etc in your lisp and it returns a value I use it as a global request defun for any lisp I write, press any key for Yes except this is No. The advantage is the calling lisp only has 3 lines all the loading dcl code is in the Getval.lsp so makes writing new lisp easier Quote Link to comment Share on other sites More sharing options...
DanW Posted September 3, 2012 Share Posted September 3, 2012 Here's another way to skin the cat. Returns T if yes is pressed: (defun IS_YES_PRESSED? (title message / vlaobj result) (vl-load-com) (vl-catch-all-apply (function (lambda () (setq vlaobj (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke-method vlaobj 'popup message 0 title 4132)) ) ) ) (if vlaobj (vlax-release-object vlaobj)) (= result 6) ) ;(IS_YES_PRESSED? "My dialogue" "Please choose ....") Quote Link to comment Share on other sites More sharing options...
GP_ Posted September 3, 2012 Share Posted September 3, 2012 Here's another way to skin the cat. Returns T if yes is pressed: (defun IS_YES_PRESSED? (title message / vlaobj result) (vl-load-com) (vl-catch-all-apply (function (lambda () (setq vlaobj (vlax-create-object "WScript.Shell")) (setq result (vlax-invoke-method vlaobj 'popup message 0 title 4132)) ) ) ) (if vlaobj (vlax-release-object vlaobj)) (= result 6) ) ;(IS_YES_PRESSED? "My dialogue" "Please choose ....") similar Quote Link to comment Share on other sites More sharing options...
DanW Posted September 3, 2012 Share Posted September 3, 2012 Interesting. If I'd known that was on Lee's excellent site, I would have just linked it. Actually adapted that lisp from Bricscad's freeware vle-extension.lsp. Apologies probably should have credited it. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 3, 2012 Share Posted September 3, 2012 Interesting. If I'd known that was on Lee's excellent site, I would have just linked it. Actually adapted that lisp from Bricscad's freeware vle-extension.lsp. Apologies probably should have credited it. Thank you for the compliment Dan; though that's rather interesting to discover that such a function in the "vle-extension.lsp" is so very similar to that published on my site, I realise that the code is only a few lines, but the layout seems almost identical. I unfortunately don't have access to the vle-extension.lsp, but I would be interested to look over it. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 4, 2012 Share Posted September 4, 2012 Another example ;calling code plus return answer (setq title "Please enter dwg number") (setq width " edit_width = 15;") (setq limit " edit_limit = 12;") (ah:getval title) (setq dwgname item) ;; Input Dialog box with variable title ;; By Ah June 2012 thanks to AlanJT for source idea ;; code (ah:getval title) (defun AH:Getval (title width limit / fo) (setq fname "C://acadtemp//getval.dcl") (setq fo (open fname "w")) (write-line "ddgetval : dialog {" fo) (write-line " : row {" fo) (write-line ": edit_box {" fo) (write-line (strcat " key = " (chr 34) "sizze" (chr 34) ";") fo) (write-line (strcat " label = " (chr 34) title (chr 34) ";" ) fo) ; these can be replaced with shorter value etc ;(write-line " edit_width = 18;" fo) ;(write-line " edit_limit = 15;" fo) (write-line width fo) (write-line limit fo) (write-line " is_enabled = true;" fo) (write-line " }" fo) (write-line " }" fo) (write-line "ok_cancel;}" fo) (close fo) (setq dcl_id (load_dialog "c:\\acadtemp\\getval")) (if (not (new_dialog "ddgetval" dcl_id)) (exit)) (action_tile "sizze" "(setq item $value)(done_dialog)") (mode_tile "sizze" 3) (start_dialog) ; returns the value of item ) Quote Link to comment Share on other sites More sharing options...
mrc1986 Posted June 28, 2016 Share Posted June 28, 2016 I am new to this forum and I know that this is an older thread but I was trying to use the code that CAB had posted, awesomeness by the way, so if I need to start a new thread I can. I am trying to use the Message box and get it to wok with an IF statement to trigger events depending on if they click Yes or No. I must be missing something because I cannot get the If statement to decipher whether Yes or No is clicked. In the end it will ask the user to purge and audit the drawing when they close (I have that all coded already just need the Msgbox), so I just used two different commands to be able to tell if it was functioning correctly. Can you guys point me in the direction of what I am missing. Thanks!! ;; YesNo.lsp CAB 04.260.2008 ;; Creates a DCL file on the fly for Yes/No Prompt ;; Arguments: ;; BoxTitle = Dialog Box Title ;; Question = Question to be displayed ;; Sample Call (YesNo " My Yes No" "Do you like creating programs in AutoLISP?") ;; Returns "Yes" or "No" from user or nil if the DCL failed (defun YesNo (BoxTitle Question / Dcl_Id% Result acadfn fn fid) (if (and (or (setq fn (findfile "YesNo.dcl")) (setq acadfn (findfile "ACAD.PAT") fn (strcat (substr acadfn 1 (- (strlen acadfn) ) "YesNo.dcl"))) (setq fid (open fn "w")) ) ;; create dcl file in same directory as ACAD.PAT (progn (foreach x (list "YesNo : dialog { key = \"Title\";" " spacer;" (strcat " : text { key = \"Question\" ; width = " (itoa (+ (strlen Question) 4)) " ; alignment = centered; }") " spacer;" " : row { fixed_width = true; alignment = centered;" " : button { key = \"Yes\"; label = \"&Yes\"; is_default = true;}" " : button { key = \"No\"; label = \"&No\"; is_cancel = true;}" " }" "}" ) (princ x fid) (write-line "" fid) ) (close fid) ) ) (cond ((setq Dcl_Id% (load_dialog fn)) (new_dialog "YesNo" Dcl_Id%) (set_tile "Title" BoxTitle) (set_tile "Question" Question) (action_tile "Yes" "(done_dialog 1)") (action_tile "No" "(done_dialog 0)") (setq Result (start_dialog)) (unload_dialog Dcl_Id%) ; Unload Dialog (if (and Result (= Result 1)) "Yes" "No") ) (t nil) ) ) (IF (yesno "Purg audit""message goes here") = yes) (command "line") (command "circle") ) Quote Link to comment Share on other sites More sharing options...
mrc1986 Posted June 28, 2016 Share Posted June 28, 2016 Just did not bang my head enough... was using the if statement incorrectly. (setq reply (yesno "Purg audit""message goes here")) (IF (= reply yes) (command "line") (command "circle") ) Quote Link to comment Share on other sites More sharing options...
pkenewell Posted June 28, 2016 Share Posted June 28, 2016 Just did not bang my head enough... was using the if statement incorrectly. (setq reply (yesno "Purg audit""message goes here")) (IF (= reply yes) (command "line") (command "circle") ) The YES in your if statement needs to be a string and match the case. You also need to complete your command statements: (if (= reply "Yes") (command "line" pause pause "") (command "Circle" Pause Pause) ) Quote Link to comment Share on other sites More sharing options...
mrc1986 Posted June 28, 2016 Share Posted June 28, 2016 Thank you the "Yes" made a we bit of a difference. I am a bit green to the more in-depth Lisp functions. I also added a check to see if it was a brand new drawing that had not been saved, otherwise it was trying to save the file randomly. I believe we are going to add this to our acad2014doc.Lisp files so that creates a way to make sure people are auditing and purging drawings. Here is what that final Lisp ended up becoming: ;; YesNo.lsp CAB 04.260.2008 ;; Creates a DCL file on the fly for Yes/No Prompt ;; Arguments: ;; BoxTitle = Dialog Box Title ;; Question = Question to be displayed ;; Sample Call (YesNo " My Yes No" "Do you like creating programs in AutoLISP?") ;; Returns "Yes" or "No" from user or nil if the DCL failed (defun YesNo (BoxTitle Question / Dcl_Id% Result acadfn fn fid) (if (and (or (setq fn (findfile "YesNo.dcl")) (setq acadfn (findfile "ACAD.PAT") fn (strcat (substr acadfn 1 (- (strlen acadfn) ) "YesNo.dcl"))) (setq fid (open fn "w")) ) ;; create dcl file in same directory as ACAD.PAT (progn (foreach x (list "YesNo : dialog { key = \"Title\";" " spacer;" (strcat " : text { key = \"Question\" ; width = " (itoa (+ (strlen Question) 4)) " ; alignment = centered; }") " spacer;" " : row { fixed_width = true; alignment = centered;" " : button { key = \"Yes\"; label = \"&Yes\"; is_default = true;}" " : button { key = \"No\"; label = \"&No\"; is_cancel = true;}" " }" "}" ) (princ x fid) (write-line "" fid) ) (close fid) ) ) (cond ((setq Dcl_Id% (load_dialog fn)) (new_dialog "YesNo" Dcl_Id%) (set_tile "Title" BoxTitle) (set_tile "Question" Question) (action_tile "Yes" "(done_dialog 1)") (action_tile "No" "(done_dialog 0)") (setq Result (start_dialog)) (unload_dialog Dcl_Id%) ; Unload Dialog (if (and Result (= Result 1)) "Yes" "No") ) (t nil) ) ) (vl-load-com) (defun Create_Close_Reactor() (if(not close:reactor) (setq close:reactor (vlr-editor-reactor nil '((:vlr-beginClose . CloseReaction)))) ); end if (princ) ); end of Create_Close_Reactor (defun CloseReaction(args reac / actDoc) (if (zerop (getvar 'dwgtitled)) (null) (progn (setq reply (yesno "Closing" "Would you like to Audit and Purge your Drawing")) (IF (= reply "Yes") (progn (setq actDoc(vla-get-ActiveDocument (vlax-get-acad-object))) (vla-ZoomExtents(vlax-get-acad-object)) (vla-AuditInfo (vla-get-ActiveDocument (vlax-get-object "AutoCAD.Application")) :Vlax-True) (repeat 3(vla-PurgeAll actDoc)) (vla-Save actDoc) ) (progon (setq actDoc(vla-get-ActiveDocument (vlax-get-acad-object))) (vla-ZoomExtents(vlax-get-acad-object)) (vla-Save actDoc) ) ) ) ) (princ) ); end of CloseReaction (Create_Close_Reactor) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.