Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Radio Button Check

Anonymous

Radio Button Check

Anonymous
Not applicable

I created the lisp and dcl that will go into a larger lisp and I am having trouble with the check.

The dialog has the user select yes or no.  I would like if nothing is selected to put an error in the dialog "please select yes or no".  This is in my program but it is not working.  Then on completion an alert pops up that says "You selected yes" if yes is selected and vise versa.  This is in there too but not working.  Any help would be much appreciated.

 

yesno.png

0 Likes
Reply
Accepted solutions (1)
1,994 Views
8 Replies
Replies (8)

john.uhden
Mentor
Mentor

Since there are only two (2) choices, I think you don't need radio buttons at all.  Rather jut a button for "Yes" and a button for "No."

 

(action_tile "Yes" "(done_dialog 1)")

(action_tile "No" "(done_dialog 0)")

(setq Action (start_dialog))

 

(if (= Action 1)

  (do_this)

  (do_that)

)

 

Plus, you can make either of the buttons the default, so the user can just hit Enter to accept the default.

John F. Uhden

0 Likes

Anonymous
Not applicable

I tried to simplify but I think I got it all mixed up now.  I changed to just two buttons yes and no, and then a cancel button.

 

YES.png

 

 


(defun c:yesno (/)


   (setq dcl_id (load_dialog "yesno.dcl"))


   (if (not (new_dialog "yesno" dcl_id))

     (exit)

   );if

;*********************************

 


(action_tile "Yes" (setq P1 "YES")(done_dialog))

(action_tile "No" (setq P1 "NO")(done_dialog))

(action_tile "cancel" "(done_dialog)")

 

 (start_dialog)


(unload_dialog dcl_id)

 

 

(if (= P1 "YES")(progn (alert (strcat "Your answer was Yes"))))

(if (= P1 "NO")(progn (alert (strcat "Your answer was no"))))

 

 

 );defun

 (princ)

0 Likes

scot-65
Advisor
Advisor
Without looking at your code, assign a key to the radio button
container (in this case a radio row). When the OK button is
selected, check to see if either of the radio button's key value
is returned. If nil, then no button was selected.

:radio_row {key="Rad00";
:radio_button {key="Rad01";}
:radio_button {key="Rad02";}
}

(get_tile "Rad00")

[this is also how one sets the tile:
(set_tile "Rad00" "Rad01") ]

???

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


0 Likes

john.uhden
Mentor
Mentor
You don't need a "Cancel" button as I presume a "No" is sufficient not to
proceed. Please follow my suggested style of getting the "Action." It
will make your life simpler and clearer, even if @ВeekeeCZ disagrees "just
because he/she wants to."

John F. Uhden

0 Likes

phanaem
Collaborator
Collaborator
Accepted solution

First, you can use an un-localized variable (or env. var., or a dictionary) to initiate and remember the answer.

I know, forcing the user to actually select Yes or No, it takes the responsibility from your shoulders.

 

I use radio buttons only if I have more than 2 options.

For yes/no, I use toggle. It is much simple in dcl and in lisp as well.

 

(defun c:yesno ( / dcl_id r)
  (if
    (and
      (> (setq dcl_id (load_dialog "yesno.dcl")) 0)
      (new_dialog "yesno1" dcl_id)
    )
    (progn
      (or *change* (setq *change* "0"))
      
      (action_tile "change" "(setq *change* $value)")
      
      (set_tile "change" *change*)
      
      (setq r (start_dialog))
      (unload_dialog dcl_id)
    )
  )
  (cond
    ((not r) nil)
    ((= r 0) (princ "\nCanceled by the user."))
    (t (alert
         (strcat
           "Your answer was "
           (cdr (assoc *change* '(("0" . "NO.") ("1" . "YES"))))
         )
       )
    )
  )
  (princ)
)

and the dcl

 

yesno1 : dialog { label = "Select YES or NO";
   : column {
       : toggle {label = "Make Changes to all Blocks"; key = "change";}
       ok_cancel;
   }
 }

 

Anonymous
Not applicable

Thanks a bunch that was what I was looking for, I guess I was making too complicated. 

It should work great in the rest of the program.

0 Likes

scot-65
Advisor
Advisor

Using your original layout there is yet another method

that you may want to investigate. It involves using mode_tile

and may appear more professional.

 

The first item is to create your own OK_cancel cluster in the

DCL file and assign the key="cancel"; to also have is_default=true;.

Button widths are typically 12.0 with a 1.0 or a 2.0 spacer in

between. Wrap inside a row container where the container's

attributes are fixed_width=true; and alignment=centered;.

 

In the LISP part, between new and start dialog, there are

typically four areas to the dialog's design.

(new_dialog dcl_id)

;* Initialize *

;* Set Tile *

;* Mode Tile *

;* Action Tile *

(setq sd (start_dialog))

 

For your dialog, the initialize and set tile sections is not needed.

 

Add this to the mode tile section:

(mode_tile "accept" 1)

 

Add these to the action tile section:

(action_tile "Rad01" "(mode_tile \"accept\" 0)")

(action_tile "Rad02" "(mode_tile \"accept\" 0)")

 

Match the keys in both mode and action to what you have

defined. Remember, these keys are text-case sensitive.

 

???

 


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


0 Likes

AntiqueAlan
Contributor
Contributor

To make it even simpler you could just put text in the dialog box and say "Pick OK to make Changes to All blocks or Cancel".

0 Likes