Jump to content

Is it possible to have a DCL without an OK and Cancel Button?


Recommended Posts

Posted

Would it be possible to have a DCL that does not have an OK and Cancel Button? I took it out on the example below, I get a dialog has neither an OK nor cancel button.

 

I am curious if I could Use the X at the top left corner to cancel out the dcl.

 

dbda_dialog : dialog {
    label = "test";
    : row {
        : column {
            : text {
                label = "Left Value:";
            }
            : edit_box {
                key = "left_value";
                edit_width = 10;
            }
        }
        : column {
            : text {
                label = "Right Value:";
            }
            : edit_box {
                key = "right_value";
                edit_width = 10;
            }
        }
    }
    : row {
        : spacer {}
        : button {
            label = "Apply Left";
            key = "apply_left";
        }
        : button {
            label = "Apply Right";
            key = "apply_right";
        }
    }
}

 

Posted

short answer is no , red x is red flag

you can have invisible button , I made two : one for space and one for q

thing is , they probably wont work as long as focus is on one of the edit boxes. So you first click outside them if you entered something there.

For the buttons it's easier , after button has done its thing , I put focus back on invisible space button (wow , is it just me or sounded that alien?)

here is something to play with.. (oh that just sounded dirty , awel , a dirty mind is a joy 4ever)

(defun c:test  (/ dcl des left right)
  (cond
    ((not (setq dcl (vl-filename-mktemp nil nil ".dcl") des (open dcl "w")))
     (princ "\nUnable to open DCL for writing."))
    ((progn (foreach str (dcl-lst) (write-line str des))
       (setq des (close des) dch (load_dialog dcl))(<= dch 0))(princ "\nUnable to load DCL file."))
    ((not (new_dialog "dbda" dch)) (princ "\nUnable to display 'dbda' dialog."))
    (t
     (set_tile "left_value" "Left")(action_tile "left_value" "(setq left $value)(mode_tile \"ib_ok\" 2)")
     (set_tile "right_value" "Right")(action_tile "right_value" "(setq right $value)(mode_tile \"ib_ok\" 2)")
     (action_tile "apply_left" "(alert \"Apply Left\")(mode_tile \"ib_ok\" 2)")
     (action_tile "apply_right" "(alert \"Apply Right\")(mode_tile \"ib_ok\" 2)")
     (action_tile "ib_ok" "(done_dialog)")
     (action_tile "ib_q" "(done_dialog)")
     (mode_tile "ib_ok" 2)
     (start_dialog))
  )
  (princ)
)


(defun dcl-lst ()
  (list
    "dbda :dialog {label=\"test\";"
    "  : row {"
    "    : column {: text {label=\"Left Value:\";}: edit_box {key=\"left_value\";edit_width=10;}}"
    "    : column {: text {label=\"Right Value:\";}: edit_box {key=\"right_value\"; edit_width=10;}}"
    "    : row {spacer;:button {label=\"Apply Left\";key=\"apply_left\";}:button {label=\"Apply Right\";key=\"apply_right\";}}"
    "  }"
    "  :image_button {fixed_height=true;height=0.001;color=dialog_background;is_default=true;key=\"ib_ok\";}"
    "  :image_button {color=dialog_background;width=0.1;height=0.1;fixed_height=true;key=\"ib_q\";label=\"&q\";}"
    "}"
  )
)

 

Posted

Likewise, DCL needs to know it can close 'properly' - it wants a button. As above there are ways to hide buttons. Can I ask what you are trying to do?

Posted

The Left and Right Buttons are for executing the commands I want, but I do not want the user to select the OK button. Maybe its not a big deal to show the cancel button either.

Posted (edited)

you can let your buttons do a done_dialog and do their thing , but every dialog needs an exit strategy so assign is_default=true to those buttons , like I did for the invisible buttons

 

only problem with this is how do you exit / cancel without doing anything.

for that create a single button with is_default=true and call it 'Exit' or 'Never Mind'

Edited by rlx
Posted

One tile should have the is_cancel attribute for the 'x' button to remain operational; note that the same tile can have both is_default & is_cancel.

  • Like 1
  • Agree 1
Posted

So if you press left or right, will that cancel the DCL? In which case have them as OK / Cancel just with a different name... but as RLX... an exit or never mind option too?

  • Like 1
Posted

Using a very small height and width for the button?

  • Like 1
Posted (edited)
3 hours ago, Steven P said:

Using a very small height and width for the button?

 

Exactly - and using an image_button in place of a regular button.

Edited by Lee Mac
  • Like 2
Posted

Thanks Lee,

 

 

(many years later and slowly working out how your mind works with these things)

  • Like 1
Posted

Thank you everyone for your ideas. With buttons, I have a button that I want to be able to select an object (ssget). Currently, it activates the selection but i cannot seem to get the dcl to unload so It locks up CAD. Any ideas on that possibly?

 

(defun doButton(a)
  (cond
    ;; Button 1: Select objects and process them
    ((= a 1)
     (if (setq ss (ssget (list (cons 0 "INSERT")))) ; Check if objects are selected
         (progn
           ;; Process the selection (replace this with actual logic)
           (alert (strcat "Button 1 was pressed! Selected " 
                          (itoa (sslength ss)) 
                          " object(s)."))
         )
         (alert "No objects selected for Button 1.") ; Handle no selection
     )
    )
    ;; Button 2: Show alert
    ((= a 2) (alert "Button 2 was pressed!"))
    ;; Button 3: Show alert
    ((= a 3) (alert "Button 3 was pressed!"))
    ;; Default case: Handle unknown button values
    (t (alert "Unknown button action!"))
  )
)


(defun C:SAMPLE1()
  ;; Load the DCL file
  (setq dcl_id (load_dialog "SAMPLE1.dcl"))

  ;; Load the dialog definition if it is not already loaded
  (if (not (new_dialog "SAMPLE1" dcl_id)) (exit))

  ;; Map buttons to their respective actions
  (action_tile "but1" "(doButton 1)")
  (action_tile "but2" "(doButton 2)")
  (action_tile "but3" "(doButton 3)")
  (action_tile "cancel" "(done_dialog)")

  ;; Display the dialog box
  (setq result (start_dialog))

  ;; Unload the dialog box
  (unload_dialog dcl_id)

  ;; Suppress the last echo for a clean exit
  (princ)
)

 

SAMPLE1 : dialog {
          label = "Sample Dialog Box Routine - Part 1";
          : column {
            : boxed_column {
              : button {
                key = "but1";
                label = "Button 1";
                is_default = false;
              }
              : button {
                key = "but2";
                label = "Button 2";
                is_default = false;
              }
              : button {
                key = "but3";
                label = "Button 3";
                is_default = false;
              }
            }
            : boxed_row {
              : button {
                key = "cancel";
                label = "Close";
                is_default = true;
                is_cancel = true;
              }
            }  
          }

}

 

Posted (edited)

You have to close the dialog in the (action_tile) statement before using (ssget). This for example can close the dialog then run your functions after the dialog closes:

(action_tile "but1" "(done_dialog)(doButton 1)")
(action_tile "but2" "(done_dialog)(doButton 2)")
(action_tile "but3" "(done_dialog)(doButton 3)")

You can also evaluate a value for (done_dialog) by using the return argument (done_dialog [int]). For example:

(defun C:SAMPLE1()
  ;; Load the DCL file
  (setq dcl_id (load_dialog "SAMPLE1.dcl"))

  ;; Load the dialog definition if it is not already loaded
  (if (not (new_dialog "SAMPLE1" dcl_id)) (exit))

  ;; Map buttons to their respective actions
  (action_tile "but1" "(done_dialog 1)")
  (action_tile "but2" "(done_dialog 2)")
  (action_tile "but3" "(done_dialog 3)")
  (action_tile "cancel" "(done_dialog 0)")

  ;; Display the dialog box
  (setq result (start_dialog))

  ;; Unload the dialog box
  (unload_dialog dcl_id)
  
  (cond
    ((= result 1)(doButton 1))
    ((= result 2)(doButton 2))
    ((= result 3)(doButton 3))
  )
  
  ;; Suppress the last echo for a clean exit
  (princ)
)

 

Edited by pkenewell
  • Like 1
Posted

That was it. I did not to think of the process like that. Thank you for the clarification!

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