The dialog dosn't work

The dialog dosn't work

amjZTCK2
Explorer Explorer
523 Views
7 Replies
Message 1 of 8

The dialog dosn't work

amjZTCK2
Explorer
Explorer

I can't figure out what's missing in my dialogbox (dcl) or connected Lisp.

The get_tile function won't give me the data from the edit_box.

The dialogbox appears and I can type a value and push OK, but no Alert and no !input ?

Do I miss anything?

0 Likes
Accepted solutions (1)
524 Views
7 Replies
Replies (7)
Message 2 of 8

DGCSCAD
Collaborator
Collaborator

See the changes below:

 

(defun c:show_dialog ( / input userclick)
  (setq dcl_id (load_dialog "dialog.dcl"))
  (if (not (new_dialog "simple_dialog" dcl_id))
    (exit)
  )
  (mode_tile "value_input" 2)
  (action_tile "value_input" "(setq input $value)")
  (action_tile "accept" "(done_dialog) (setq userclick 1)")
  (action_tile "cancel" "(done_dialog) (setq userclick nil)")
  (start_dialog)
  (unload_dialog dcl_id)
  (if (and (/= input nil) (/= input "") (= userclick 1))
      (alert (strcat "\nYou entered: " input))
  )
(princ)
)

 

simple_dialog : dialog {
    label = "Simple Dialog";
    : row {
        : column {
            : text {label = "Enter value:";}
            : edit_box {key = "value_input"; width = 20;}
        }
    }
    ok_cancel;
}
AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 3 of 8

paullimapa
Mentor
Mentor

The get_tile function only works when the dialog is still displayed. 

Since your action_tile for "ok_button" and "cancel_button" is "(done_dialog #) then the dialog is dismissed. So your following if statement with get_tile will yield nothing:

(if (= 1 (get_tile "ok_button"))

So before the dialog is dismissed, you can use the get_tile function by including this in the action_tile statement in your ok_button:

 

 

(action_tile "ok_button" "(setq input (get_tile \"value_input\"))(done_dialog 1)")

 

 

Now when you click the OK button, the get_tile function retrieves the value (string of text) from the edit_box saving to variable input before dismissing the dialog.

Another way to retrieve the value from the edit_box is to include an action_tile statement for "value_input":

 

 

(action_tile "value_input" "(setq input $value)")

 

 

So when a return or tab is used after the edit_box is filled out the current value (string of text) in the edit_box is retrieved and saved in variable input.

Now one way to use the if statement to test what button was clicked OK or Cancel, you can do this:

 

 

(setq what_clicked (start_dialog))

 

 

When OK is clicked the (done_dialog 1) will cause what_clicked to store 1

When Cancel is clicked the (done_dialog 0) will cause what_clicked to store 0

Then change your if statement to look like this:

 

 

  (if (= 1 what_clicked)
     (alert (strcat "\nYou clicked OK button & entered into edit box:\n" input))
     (alert "You clicked Cancel button")
  )

 

 

One more thing. You set the edit_box to initially have a value (string of text") of "1" with this statement:

 

 

(set_tile "value_input" "1")

 

 

I would change this to:

 

 

(set_tile "value_input" (setq input "1"))

 

 

So this would save the initial variable input to match as "1" which is the string content you're placing into the edit_box when the dialog is displayed.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 4 of 8

komondormrex
Mentor
Mentor

@amjZTCK2 

try this one

(defun c:show_dialog ()
  (setq dcl_id (load_dialog "dialog.dcl"))
  (if (not (new_dialog "simple_dialog" dcl_id))
    (exit)
  )
  (set_tile "value_input" "1")
  (action_tile "ok_button" "(setq input (get_tile \"value_input\")) (done_dialog 1)")
  (action_tile "cancel_button" "(done_dialog 0)")
  (setq dialog_result (start_dialog))
  (unload_dialog dcl_id)
  (cond
    ((= 1 dialog_result)
      (alert (strcat "\nYou entered: " input))
    )
    (t)
  )
  (princ)
)
0 Likes
Message 5 of 8

Sea-Haven
Mentor
Mentor

Just another go at it, adding the make dcl to the lsp.

 

(defun c:show_dialog ( / input userclick)
(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "W"))

(write-line "simple_dialog : dialog {" fo)
(write-line "label = \"Simple Dialog\" ; " fo)
(write-line ": column {" fo)
(write-line ": row {" fo)
(write-line "label = \"Enter value:\" ;" fo)
(write-line ": edit_box { " fo)
(write-line " key = \"value_input\" ; " fo)
(write-line " edit_width = 20 ;  " fo)
(write-line " edit_limit = 19 ; " fo)
(write-line " } " fo )
(write-line " } " fo )
(write-line "spacer_1 ;" fo)
(write-line "ok_cancel ; " fo)
(write-line " } " fo )
(write-line " } " fo )
(close fo)

  (setq dcl_id (load_dialog fname))
  (if (not (new_dialog "simple_dialog" dcl_id))
    (exit)
  )
  (mode_tile "value_input" 2)
 ; (action_tile "value_input" "(setq input $value)")
  (action_tile "accept" "(setq input (get_tile \"value_input\")) (done_dialog)")
  (action_tile "cancel" "(done_dialog)")
  (start_dialog)
  (unload_dialog dcl_id)
    
  (vl-delete-file fname)
  (princ input)
(princ)
)
(c:show_dialog)

 

There is a lisp by RLX that converts a dcl to lisp code. 

 

0 Likes
Message 6 of 8

amjZTCK2
Explorer
Explorer

Interesting solution but..

I'm sorry this doesn't work either to me.

0 Likes
Message 7 of 8

amjZTCK2
Explorer
Explorer
Accepted solution

Thank you Paul Le

And it makes sense what your are writing.

 

/Anders

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

You are welcome…cheers!!!

PS: I recently wrote an article on how these xxx_tile functions work here:

https://issuu.com/augi/docs/aw202409hr/25?ff


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes