
|
D I A L O G
C O N T R O L
L A N G U A G E
D I A L O G
C O N T R O L
L A N G U A G E
D I A L O G
C O N T R O L
L A N G U A G E |
|
The AutoLisp Tutorial - DCL Dialog Control Language - Part 5 Part 5 - Radio Buttons Let's build a working DCL file showing us exactly how to handle radio buttons. The first thing you need to know about a radio button is how stupid they are. They have no brains. They do not know what the other radio buttons are doing. You can layout six radio buttons and select everyone of them like they were toggles. That's not the way we use radio buttons. They are supposed to be smart. They should know what to do if a radio button around them is selected. They should turn themselves off because only one radio button in a group is supposed to be checked. That's where radio_column and radio_row come in to play. They are the brains for the radio buttons. They watch all the buttons in their row or column to make sure only one is turned on. We will build a DCL file containing 4 radio_buttons plus an Okay and Cancel button. The selected item will be displayed on the screen after the user presses the Okay button. Layout thoughts: I will place the radio_buttons in a column, (stacked on top of each other). Then I'll put the Okay and Cancel buttons in a row at the bottom of the dialog box. So...I'll need something like this: : column { Let's copy in the code for the header and all of the controls above from the "Controls" section of this tutorial. I'll show them in red. Notice the key names and labels had to be changed. SAMPLE5 : dialog { } Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE5.DCL Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCAD search path. Next we will get a copy of the AutoLisp model and revise it. All new code is shown in red. (defun C:SAMPLE5()
Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE5.LSP Be sure to change the "Save as Type" drop down box to "All Files" before saving it or it will put a ".txt" extension on the file name. Save this file somewhere in the AutoCAD search path. Let's load the program and see what the DCL file looks like. On the command line type this: Command: (load "sample5") and press enter You should see this C:Sample5 Now type Sample5 and press enter. If everything went according to plan you should see this on your screen:
That doesn't look very good does it? Let's change the boxed_row into a boxed_column in our DCL file. (See the blue text in the DCL file above) Make the changes then Save the Sample5.DCL file. No need to load the autolisp program again, it's loaded. Just run the Sample5 program again. Now it should look like this:
It still doesn't look right. It's our label "Sample Dialog Box Routine - Part 5" that is causing the problem. Let's shorten it to "SDBR - Part 5" and try it again:
Looks better! Looking good so far. We need to add the SaveVars function to save the selected items from the radio_column when the Okay button is pressed. Look at the blue text in the Sample5.lsp program above. Let's steal the saveVars routine from the radio_column control on the "Saving data from the dialog box" page of this tutorial and modify it. I'll show the modifications in red. We can do this two different ways. We can check each radio_button to find out which one is on or we can check the entire column of radio_buttons by getting the value of the radio_column. First method: Checking the Radio_Column: (defun saveVars() ;;;--- Get the key of the choice made (setq myChoice(get_tile "mychoice")) ) Second method: Checking each Radio_Button: (defun saveVars() ;;;--- Get the value of each item ) So...Which one do we use? For this tutorial, let's use both. Why not?
(defun saveVars() ;;;--- Get the key of the choice made (setq myChoice(get_tile "mychoice")) ;;;--- Get the value of each item ) Add this to the original Sample5.lsp program and we should have something that looks like this: (defun saveVars() ;;;--- Get the key of the choice
made (setq myChoice(get_tile "mychoice")) ;;;--- Get the value of
each item ) (defun C:SAMPLE5()
Last item. We need to replace the line in the program: (princ "\n The user pressed Okay!") with something to display the selected item. ;;;--- If the user
pressed the Okay button
;;;--- Inform the user of his selection using the radio_column data
;;;--- Inform the user of his selection using the radio_buttons data ) Add the above to the autolisp file, save it and test it out. Everything working okay?
When you get your program tested and everything is working, move the blue line above, [ (defun C:SAMPLE5() ] all the way to the top of the file. This will make all of your variables local and will reset them all to nil when the program ends. That's it. We're done. All questions/complaints/suggestions should be sent to / Last Updated May 22nd, 2013 Copyright 2002-2013 /. All rights reserved. |