Jump to content

Add a CANCEL and OK dialog box to a LISP


Recommended Posts

Posted

I have a lisp routine that runs Zoom Extents, Purge, Audit and Save twice (below) ... my question is, when typing "PNA" command, is there a way to add a dialog box that pops up to either proceed or cancel the command?

 

 

(DEFUN C:PNA ()
 (C:TA)
 (COMMAND "ZOOM" "E")
 (COMMAND "-PURGE" "A" "" "N")
 (COMMAND "AUDIT" "Y")
 (COMMAND "QSAVE")
 (COMMAND "QSAVE")
)

Posted

You could use my Popup function in the following way:

(defun c:pna nil
   (cond
       (   (null c:ta)
           (princ "\nTA command not defined.")
       )
       (   (null LM:popup)
           (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html")
       )
       (   (= 6 (LM:popup "Proceed?" "Would you like to proceed with this command?" 36))
           (c:ta)
           (command "_.zoom" "_e" "_.-purge" "_a" "" "_n" "_.audit" "_y" "_.qsave")
       )
   )
   (princ)
)

Posted

Hi Lee Mac, thanks for the modification. It did not work on my machine and maybe reason being is that the TA command is a LISP a guy created here at work. So basically what I'm trying to do is run his LISP before it can do the rest. I just want to be able to add an OK and CANCEL button at the beginning before it executes anything.

Posted

You're welcome.

 

It did not work on my machine and maybe reason being is that the TA command is a LISP a guy created here at work.

 

What happened exactly?

Do you receive an error message?

Posted (edited)

Maybe this also (acet-ui-message message [caption [type]]) where type is 1 for OKCANCEL

 

(if (= (acet-ui-message "this is test" "pick ok or Cancel" 1) 2)(exit))

Edited by BIGAL
Posted
Maybe this also (acet-ui-message message [caption [type]]) where type is 1 for OKCANCEL

 

(if (= (acet-ui-message "this is test" "pick ok or Cancel" 1) 2)(exit))

 

 

 

That's what I needed BigAl ...

(DEFUN C:PNA ()
 (if (= (acet-ui-message "This will Purge, Audit and Double Save. Ok to proceed?" "pick ok or Cancel" 1) 2)(exit))
 (C:TA)
 (COMMAND "ZOOM" "E")
 (COMMAND "-PURGE" "A" "" "N")
 (COMMAND "AUDIT" "Y")
 (COMMAND "QSAVE")
 (COMMAND "QSAVE")
)

 

 

LeeMac thanks for your help too. The error it gave me was "TA command not defined" and "popup function not defined - download this function from http://lee-mac.com/popup.html"

Posted
The error it gave me was "TA command not defined"

 

Yes, the TA function would need to be loaded - this would have equally applied to your original code.

 

...and "popup function not defined - download this function from http://lee-mac.com/popup.html"

 

Yes, you would need to download & load my Popup function from the link I provided in my above post before running the code.

 

These are not error messages (no error has occurred) - they are message for your information.

 

You can use the acet-* functions, but be mindful that these are Express Tools functions and will hence only be available if Express Tools are installed.

Posted

Lee Mac I tried using the code you provided but came back with ";error: no function definition: LM:POPUP". Even though it says MS_ACAD.lsp successfully loaded.

 

 

(defun c:pna nil
   (cond
       (   (null c:ta)
           (princ "\nTA command not defined.")
       )
       (   (null LM:popup)
           (LM:Popup "Title Text" "This is a test message." (+ 1 16 4096))
       )
       (   (= 6 (LM:popup "Proceed?" "Would you like to proceed with this command?" 36))
           (c:ta)
           (command "_.zoom" "_e" "_.-purge" "_a" "" "_n" "_.audit" "_y" "_.qsave" "_.qsave")
       )
   )
   (princ)
)

Posted
Lee Mac I tried using the code you provided but came back with ";error: no function definition: LM:POPUP". Even though it says MS_ACAD.lsp successfully loaded.

 

       (   (null LM:popup)
           (LM:Popup "Title Text" "This is a test message." (+ 1 16 4096))
       )

 

You are not using the code I originally provided - you have modified my example and you are now trying to evaluate the function under the condition that it is not defined - this will obviously error and is the very reason why my original code above included this condition accompanied by a message to state that the function must be loaded.

 

What is MS_ACAD.lsp?

Posted

MS_ACAD.lsp is the notepad file where I keep all of the lisps ... I tried putting the first one you provided:

 

 

(defun c:pna nil
   (cond
       (   (null c:ta)
           (princ "\nTA command not defined.")
       )
       (   (null LM:popup)
           (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html")
       )
       (   (= 6 (LM:popup "Proceed?" "Would you like to proceed with this command?" 36))
           (c:ta)
           (command "_.zoom" "_e" "_.-purge" "_a" "" "_n" "_.audit" "_y" "_.qsave")
       )
   )
   (princ)
)

 

 

but I got this ... LM:popup function not defined - download this function from http://lee-mac.com/popup.html

 

 

Yes, you would need to download & load my Popup function from the link I provided in my above post before running the code.

 

 

So I went to your link (amazing link by the way and can't wait to learn from it) and saw the information in there so I thought maybe you meant I needed to change this line:

 

 

...
           (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html") ;this line
...

 

 

Yes, the TA function would need to be loaded - this would have equally applied to your original code.

 

 

Well I have no idea how to do this because I am just trying to call on a lisp that this other guy created and is an .fas file. The only way I know how to use it is if I leave it before I do any command like:

 

 

(defun c:pna ()
(ta)
(command ...)

 

 

However I have no idea why there is a nil like you have it in the code.

Posted
So I went to your link and saw the information in there so I thought maybe you meant I needed to change this line:

...
           (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html") ;this line
...

 

There is no need to change any of the code: simply copy the code (including the code header) from the link I provided to your MS_ACAD.lsp or to a separate AutoLISP file and ensure that the code is loaded (and hence the function defined) before using the example program I provided.

 

You can include the code for my LM:popup function alongside the above code if you wish, e.g.:

(defun c:pna nil
   (cond
       (   (null c:ta)
           (princ "\nTA command not defined.")
       )
       (   (null LM:popup)
           (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html")
       )
       (   (= 6 (LM:popup "Proceed?" "Would you like to proceed with this command?" 36))
           (c:ta)
           (command "_.zoom" "_e" "_.-purge" "_a" "" "_n" "_.audit" "_y" "_.qsave")
       )
   )
   (princ)
)

;;-------------------------=={ Popup }==----------------------;;
;;                                                            ;;
;;  Displays a pop-up message box prompting the user.         ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2012 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  title - Text to be displayed in the pop-up title bar      ;;
;;  msg   - Text content of the pop-up message box            ;;
;;  flags - Integer indicating icon & button appearance       ;;
;;          Reference: http://lee-mac.com/popup.html          ;;
;;------------------------------------------------------------;;
;;  Returns:  Integer indicating the button pressed to exit   ;;
;;------------------------------------------------------------;;

(defun LM:popup ( title msg flags / wsh res )
   (if (setq wsh (vlax-create-object "wscript.shell"))
       (progn
           (setq res (vl-catch-all-apply 'vlax-invoke-method (list wsh 'popup msg 0 title flags)))
           (vlax-release-object wsh)
           (if (null (vl-catch-all-error-p res))
               res
           )
       )
   )
)

(amazing link by the way and can't wait to learn from it)

 

Thanks - I'm glad you like my site :beer:

 

Well I have no idea how to do this because I am just trying to call on a lisp that this other guy created and is an .fas file.

 

That changes things - if your colleague compiled the program to a separate namespace FAS file then you will not be able to call the function from another program, as the function will not be exposed to the document namespace.

Posted

That changes things - if your colleague compiled the program to a separate namespace FAS file then you will not be able to call the function from another program, as the function will not be exposed to the document namespace.

 

Well I was able to call it before by doing the original code

(DEFUN C:PNA ()
 (C:TA)
...

 

 

We are able to load it in our AutoCAD from the Load/Unload Applications and it's in the Contents ... I just want to be able to call use that before all the other stuff. Isn't there a way to call it like I had it above? I wanted to modify the code you gave me by putting the c:TA before the rest of the code but I'm afraid I will screw it up somehow lol

Posted

I think it's actually working. It does call the TA command which is THAW ALL lol. Thanks Lee Mac :D

Posted
I think it's actually working. It does call the TA command which is THAW ALL lol. Thanks Lee Mac :D

 

If it's only a 'thaw-all' program, you might as well simply use:

(defun c:pna nil
   (if LM:popup
       (if (= 6 (LM:popup "Proceed?" "Would you like to proceed with this command?" 36))
           (command "_.-layer" "_t" "*" "" "_.zoom" "_e" "_.-purge" "_a" "" "_n" "_.audit" "_y" "_.qsave")
       )
       (princ "\nLM:popup function not defined - download this function from http://lee-mac.com/popup.html")
   )
   (princ)
)

Posted

So if the lisp is calling out to use it from an html source. What happens if your server goes down or wherever it is grabbing it from? Will it still work or will it just cause an error message?

Posted
So if the lisp is calling out to use it from an html source. What happens if your server goes down or wherever it is grabbing it from? Will it still work or will it just cause an error message?

 

The program is not automatically downloading the function from my site (though, that would be possible) or accessing the function from my site - in these examples, the code for the relevant supporting functions would need to be downloaded and included with the program.

Posted

You're the best. Thanks for always being there to help Lee :)

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