The AutoLisp Tutorial - DCL
Dialog Control Language - SaveVars
In this section we are going to take a look at the SaveVars routine and disect it for each type of control. The types of controls that we need to save are :
Edit_box - List_box - Popup_List - Radio_Buttons - Radio_Column - Radio_Row - Toggle
The SaveVars routine is executed just before the dialog box is issued a done_dialog call. You cannot get the data from the dialog box once it has been shut down. If you remember our action calls in the AutoLisp Program, they looked something like this:
;;;--- If an action event occurs, do this
function
(action_tile "accept" "(saveVars)(done_dialog)")
Notice the (saveVars) is just before the (done_dialog). This is the proper order. The settings from the dialog box will be saved just before it is shut down.
The SaveVars routine always has the same definition:
(defun saveVars()
;stuff here
)
That's the shell. We need to work on the "stuffing". Let's get to it.
Important note before we get started: You use the GET_TILE function to get the data from the dialog box controls. All values returned from the dialog box controls will be a string. You will have to convert the string into whatever data you need. For example, and edit_box returns a string. That is fine if you want the user to enter a layer name. But if you are asking for a distance, a string will not do you much good. You will have to convert the string into a number.
Conversion | AutoLisp Code in the SaveVars routine |
String to Real number | (setq myReal (distof (get_tile "mykey"))) |
String to Integer | (setq myInt (atoi (get_tile "mykey"))) |
String to String | (setq myStr (get_tile "mykey")) |
Stuffing
There are three parts to a control with an action call back statement.
1. The DCL definition
2. The action call in the AutoLisp file.
3. The code inside the SaveVars routine.
In each of the following controls I will show you all three parts so we know how to put it all together later. Although, all of the parts are important, try to focus on the SaveVars routine.
Edit_box - List_Box_Single_Selection - List_Box_Multiple_Selection - Popup_List
Radio_Column - Radio_Row - Toggle - Ok_Cancel
1 |
: edit_box { key = "edbox"; label = "Bolt Circle Diameter:"; edit_width = 8; value = "10"; } |
|
2 |
No Action call required. We will get the data the user typed when we use the SaveVars routine. But, if your deadset about doing something when the user types in the edit box, here you go: (action_tile "edbox" "(doThisFunction)")
|
|
3 |
To get the data as a real number: (defun saveVars() (setq edBox(distof(get_tile "edbox"))) ) |
To get the data as a string: (defun saveVars() (setq edBox(get_tile "edbox")) ) |
NOTE: Notice I used the key name as the variable to store the data in. You will find this method makes it easier to keep things straight. DCL is case sensitive so, I never capitalize key names, only autolisp variable names if they are made up of more than one word.
Like this: AutoLispVariable name = layerList
DCL Key name = "layerlist"
Note About LIST_BOX and POPUP_LIST
When you use the get_tile function on a list_box or popup_list it will return the index of the selected item as a string. The first item is "0". The second item is "1". You need to convert this to an integer (atoi "0") and then use the NTH function on the original list to get the actual name selected. In other words, if the user selects the third item in the list_box, this is also the third item in the list that was used to put the items in the list_box.
1 |
: list_box { key = "mylist"; label = "Available Choices"; multiple_select = "FALSE"; // Sets single selection width = 40; height = 20; fixed_width_font = true; // Equally spaced characters value = ""; // Start with no item selected } |
2 |
No Action call required. We will get the selected
item when we use the SaveVars routine. But, sometimes you need to change things in
the dialog box if the user makes a selection, so: (action_tile "edbox" "(doThisFunction)") |
3 |
(defun saveVars() ;;;--- Get the selected item from the list )
1. This should only be used when single selection is required. This will not work on multiple selection. 2. This is assuming there is a list of items called myList. 3. See Note. |
1 |
: list_box { key = "mylist"; label = "Available Choices"; multiple_select = "TRUE"; // Sets multiple selection width = 40; height = 20; fixed_width_font = false; // Use default font [ no alignment ] value = "4"; // Start with item 5 selected. } |
2 |
No Action call required. We will get the selected
items when we use the SaveVars routine. But, sometimes you need to change things in
the dialog box if the user makes a selection, so: (action_tile "mylist" "(doThisFunction)") |
3 |
(defun saveVars(/ readlist count item) ;;;--- Setup a list to hold the selected items (setq retList(list)) ;;;--- Save the list setting (setq readlist(get_tile "files")) ;;;--- Setup a variable to run through the list (setq count 1) ;;;--- cycle through the list getting all of the selected items (while (setq item (read readlist)) (setq retlist(append retList (list (nth item fileNames)))) (while (and (/= " " (substr readlist count 1)) (/= "" (substr readlist count 1)) ) (setq count (1+ count)) ) (setq readlist (substr readlist count)) ) ) Note: This method can be used for a single or multiple selection list_box. See Note. |
1 |
: popup_list { key = "mylist"; // action key fixed_width_font = false; // fixed width font off width = 20; // width of popup list height = 20; // height of popup list } |
2 |
No Action call required. We will get the selected
item when we use the SaveVars routine. But, sometimes you need to change things in
the dialog box if the user makes a selection, so: (action_tile "mylist" "(doThisFunction)") |
3 |
(defun saveVars() ;;;--- Get the selected item from the list (if(= sStr "") (setq myItem nil) (setq myItem (nth (atoi sStr) myList)) ) See Note. |
Radio_Column and
Radio_Buttons
1 |
: radio_column {
// Use boxed_radio_column if a box is
required. label = "Choices"; // Label for the column or boxed_column key = "choices"; // Action key for the radio column : radio_button {
// First radio button : radio_button { //
Second radio button : radio_button { //
Third radio button : radio_button { //
Fourth radio button } // Close the radio_column |
2 |
No Action call required. We will get the selected
item when we use the SaveVars routine. But, sometimes you need to change things in
the dialog box if the user makes a selection, so: (action_tile "choices" "(doThisFunction)") // If any choice is made (action_tile "choice1" "(doThatFunction)") // If choice1 is made (action_tile "choice2" "(doDisFunction)") // If choice2 is made etc. |
3 |
(defun saveVars() ;;;--- Get the key of the choice made (setq choicesVal(get_tile "choices")) ) OR (defun saveVars() ;;;--- Get the value of each item ) |
Radio_Row And Radio_Buttons
1 |
: radio_row {
// Use
boxed_radio_row if a box is required. label = "Choices"; // Label for the row or boxed_row key = "choices"; // Action key for the radio row : radio_button
{ // First radio button : radio_button { //
Second radio button : radio_button { //
Third radio button : radio_button { //
Fourth radio button } // Close the radio_row |
2 |
No Action call required. We will get the selected
item when we use the SaveVars routine. But, sometimes you need to change things in
the dialog box if the user makes a selection, so: (action_tile "choices" "(doThisFunction)") // If any choice is made (action_tile "choice1" "(doThatFunction)") // If choice1 is made (action_tile "choice2" "(doDisFunction)") // If choice2 is made etc. |
3 |
(defun saveVars() ;;;--- Get the key of the choice made (setq choicesVal(get_tile "choices")) ) OR (defun saveVars() ;;;--- Get the value of each item ) |
1 |
: toggle { key = "tog1"; // Action key label = "Name"; // Label } |
2 |
No Action call required. We will get the value of
the toggle when we use the SaveVars routine. But, sometimes you need to change
things in the dialog box if the user makes a selection, so: (action_tile "tog1" "(doThisFunction)") |
3 |
(defun saveVars() ;;;--- Get the selected item from the radio column ) |
1 |
ok_cancel;
// Only one line required Note: I usually define my own okay and cancel buttons using two standard buttons, but this works fine. |
2 |
You will need two action calls for this button...both close the dialog box
but the accept or "Okay" key will save the dialog box settings before shutting
the dialog box down. (action_tile "cancel" "(setq ddiag 1)(done_dialog)") (action_tile "accept" "(setq ddiag 2)(saveVars)(done_dialog)") Ahh....finally the SaveVars routine shows up. |
3 |
Nothing to do in the saveVars routine for these buttons. |