Jump to content

Alert Input Box


jmerch

Recommended Posts

I've searched what I could and can't find my answer. Is there a LISP function similar to "alert" but instead of just the pop-up box it let's the user input something there (instead of using "prompt" in LISP)?

Link to comment
Share on other sites

Thought it'd be fun to write an example:

 

(defun PromptBox ( title msg / dcl dch file val )

 ;; ------------------------------------------- ;;
 ;; Arguments:-                                 ;;
 ;; ------------------------------------------- ;;
 ;; title - Dialog Box Title                    ;;
 ;; msg   - [Optional] Text to Display          ;;
 ;; ------------------------------------------- ;;
 ;; Returns:-                                   ;;
 ;; ------------------------------------------- ;;
 ;; Entered String if user presses OK, else nil ;;
 ;; ------------------------------------------- ;;
 ;; Example by Lee Mac 2010  -  www.lee-mac.com ;;
 ;; ------------------------------------------- ;;

 (cond
   (
     (not
       (and
         (setq dcl  (vl-filename-mktemp nil nil ".dcl"))
         (setq file (open dcl "w"))
         (progn
           (write-line
             (strcat
               "promptbox : dialog { label = \"" title "\"; initial_focus = \"txt\"; spacer;"
               ": edit_box { key = \"txt\"; edit_width = 60; edit_limit = 2048; allow_accept = true; } spacer; ok_cancel; }"
             )
             file
           )
           (setq file (close file))
           (findfile dcl)
         )
       )
     )
   )
   (
     (<= (setq dch (load_dialog dcl)) 0)

     (vl-file-delete dcl)
   )
   (
     (not (new_dialog "promptbox" dch))

     (unload_dialog dch)
     (vl-file-delete dcl)
   )
   (t
     (if msg (setq val (set_tile "txt" msg)))

     (action_tile "txt" "(setq val $value)")

     (if (zerop (start_dialog)) (setq val nil))

     (unload_dialog dch)
     (vl-file-delete dcl)
   )
 )

 val
)

  • Like 1
Link to comment
Share on other sites

@alanjt - Gotcha, will give that a try. Thanx.

 

@lee - I can understand most of that but will disect it later. It looks like you're having LISP write the DCL which I think is very funny and cool. I did take a gander at AfraLISP's DCL beginner guide and may have what I need to get me going. But am still intrigued at your direction with this.

Link to comment
Share on other sites

@lee - I can understand most of that but will disect it later. It looks like you're having LISP write the DCL which I think is very funny and cool. I did take a gander at AfraLISP's DCL beginner guide and may have what I need to get me going. But am still intrigued at your direction with this.

 

Yes, the DCL file is written to a temporary filename generated by vl-filename-mktemp, this file is then deleted following function completion.

 

You can test it with something like:

 

(PromptBox "Information" "AutoLISP is Fun")

Or maybe:

 

(PromptBox "Title" nil)

Lee

  • Like 1
Link to comment
Share on other sites

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