Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Alert Box That Takes User Input

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
btillman
3654 Views, 13 Replies

Alert Box That Takes User Input

Is there a way to have an alert box pop up at a certain point in the code which gives the user a chance to cancel the LISP program and not proceed any further?

 

13 REPLIES 13
Message 2 of 14
_Tharwat
in reply to: btillman

Example ....

 

(if (not point )
(progn
(alert "Something went wrong !!")
(exit)
)
)

 

Message 3 of 14
Kent1Cooper
in reply to: btillman


@btillman wrote:

Is there a way to have an alert box pop up at a certain point in the code which gives the user a chance to cancel the LISP program and not proceed any further?

 


I believe all you get for User input at an (alert) is the OK button.  You can easily have a cancellation always associated with that if appropriate [which it doesn't sound like it is in this case], such as:

 

(if (...there's something invalid...)

  (progn

    (alert "That is not valid, you idiot!")

    (quit)

  ); progn

); if

 

BUT, if you want them to have the choice of whether to or not to cancel, I think you need to give them that choice at the Command: prompt line, and use the (alert) to call the User's attention to the need to make that choice, e.g. something like this rather elaborate approach [slightly altered excerpt from a longer routine] about a locked Layer, that saves their choice in a global *unlk* variable and offers it as a default if the question comes up again:

 

....

    (if (....result from earlier check on whether an object's Layer is locked....)

      (progn ; then - ask whether to unlock

        (alert "Layer is locked.  See choices at Command: prompt line.")
        (initget "Proceed Quit")
        (setq
          unlktemp
            (getkword
              (strcat
                "\nLayer is locked; temporarily unlock and Proceed, or Quit? [P/Q] <"
                (if *unlk* (substr *unlk* 1 1) "P"); at first use, Proceed default; otherwise, prior choice
                ">: "
              ); end strcat
            ); end getkword & unlktemp
          *unlk*
            (cond
              (unlktemp); if User typed something, use it
              (*unlk*); if Enter and there's a prior choice, keep that
              (T "Proceed"); otherwise [Enter on first use], Proceed
            ); end cond & *unlk*
        ); setq
        (if (= *unlk* "Proceed")
          (command "_.layer" "_unlock" *pathlay* ""); then [*pathlay* = variable with Layer of 'path' object]
          (progn (...perform a resetting subroutine...) (quit)); else
        ); if
      ); progn

    ); if

    (.... go on to process object if preceding didn't result in (quit) ....)

    (.... re-lock that Layer ....)
....

 

But you can certainly do something less complex than that, using a similar but simpler (alert)-and-get-User-input approach.

 

You can probably also do it all in a dialog box by defining one with DCL, but I'm not experienced enough in that, so someone else would need to guide you.

Kent Cooper, AIA
Message 4 of 14
scot-65
in reply to: btillman

>>which gives the user a chance to cancel the LISP program

 

I take this as either Yes, proceed with error -or- No, stop the program.

 

One can easily create a dialog that mimics the alert box to offer additional

buttons as to how to proceed. I can think of "Use Default" and "Cancel" buttons

after the message body.

 

If you want to expand on this, provide an edit box to capture the correct entry

(with the incorrect entry showing and highlighted). But be careful, the edit_box

returns a string and you will have to test this accordingly for lists, reals, or integers, etc.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 5 of 14
dbroad
in reply to: btillman

I agree with the others that command line approach is more consistent with AutoCAD command process but this link >>>>here<<<<< has what you need.  Just push the "download this tip" and use the included lisp and dialog file.

Architect, Registered NC, VA, SC, & GA.
Message 6 of 14
diagodose2009
in reply to: btillman

Dear sir...

step1) Please  load my application "desmo_all28dcl.vlx"

step2) You enter thecommand "2" enter o (defun  C:2 (/ )

step3) Please select option 08) lpsnf_dcl_getpoint

 

if you need the source please send to me the private message,.

 

http://www.puiubrat.3x.ro/lisp2arx/vlxdemos/demos_all28dcl.VLX

 

 

 

Message 7 of 14
btillman
in reply to: diagodose2009

Thanks very  much for all of these replies. I am taking all options into consideration here.

 

Diagodose2009, I would be very interested in seeing what you have recommended, however, may I make the following suggestion. The link you provided took me to a site which while I was not blocked by the corporate firewall, there were several images on there which made me immediately close the browser window. In a professional environment, such things can get a working person into real trouble and these days one cannot take those kinds of risks. I would tend to believe that your link is innocuous but the images which I saw were an immediate reason to shut things down. Please understand that I am offering this only as constructive advice. In the business world there is just no place for taking on-line risks.

Message 8 of 14
balisteor
in reply to: btillman

Lee Mac has made something simple that works well for this type of thing, You can even have a continue button. : )

 

This is a safe link to click on too.....   Lee Mac's POPUP solution.

 

 

 

 

 

 

Message 9 of 14
btillman
in reply to: balisteor

Yes indeed, Lee-Mac makes some very cool code. I can't seem to get this one working. I copied the code into my IDE and called it like this:

 

(vl-load-com)
(defun c:test ()
  (LM:Popup "Title Text" "This is a test message." (+ 2 48 4096))
)

 But when I run test I don't seem to get anything on my screen. Is there something I'm missing?

Message 10 of 14
balisteor
in reply to: btillman

Sorry for late response, Ill be back in early tommorow. Check to see what error (if any) you get on the command line from running it.

Message 11 of 14
btillman
in reply to: btillman

No error messages of any kind showed up. The screen blinked a little and then nothing. I copied the same code on my home machine this morning and it worked great. I will double check the syntax on my office computer when I get there in a couple of more hours. The IT crew does have certain policies enforced...I wonder if they limit windows scripting but my machine has a pretty open policy because I do development for them.

Message 12 of 14
balisteor
in reply to: btillman

I'm unsure of the cause, it looks as if other people have had similar issues, but I cannot find a solution yet. perhaps as you suggested something is blocking it.

 

You could use the command line as others have suggested, or make a dialog using DCL. Someday perhaps autodesk will make an alert box with a few more options.

 

In my opinion I do not like to have users respond on command line, first its hard for them to notice because some people don't pay attention to command line, and second I've noticed lately that a few users even keep their command line closed and don't have any interest in using it anymore. So the best way to get their attention is a popup box.

 

If you must have a popup and don't want to use DCL, both  doslib, and opendcl are a couple of great free tools that work well with autocad, they are very simple to use and have plenty of tools for these types of situations.

 

 

 

Message 13 of 14
btillman
in reply to: balisteor

I know what you mean about users and their custom settings. When I first came here in January they told me all about the strict standards in place.....yeah right. And as in the past I have found that tweaking users' custom settings will put you on the S-List real fast and all kinds of nasty rumors will be spread about your lack of capabillity to do your job properly. Kind of like this year's Presidential campaining....sheesh!

 

I never did get the issue resolved with my corporate AC 2009 computer. When the command which runs so well on all other computers is run on this one I get:

 

; error: bad argument type: VLA-OBJECT nil

 

So I just move to another computer to complete my development work. I am convinced that if I could wipe this hard drive clean and do a fresh install of the OS and AutoCAD it would almost certainly clear up the matter. But the IT people look at me like they just seen a ghost when I mention doing this. So for now at least I think we can consider this thread closed.

 

 

 

Message 14 of 14
johncavogt
in reply to: btillman

I tested the Lee-Mac code by just pasting it into the command line of 2011 Architecture, and it worked, so I'd say it's not in the code that you have a problem.

 

This seems to have more versatility, but you might find the msgbox function in the doslib tools from McNeel more easily implemented, aside from getting all the cool other functions, too.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost