jpsheader.jpg (29354 bytes)

Back to DCL Tutorial Homepage

Back to AutoLisp Homepage

Back to JefferyPSanders.com

 

 

 

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 - 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 sometimes 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 1)")

  Notice the (saveVars) is just before the (done_dialog 1).  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.


  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


  Edit_Box

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

 


List_Box  Single Choice Only

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
  (setq sStr(get_tile "mylist"))

  ;;;--- If the index of the selected item is not "" then something was selected
  (if(/= sStr "")
    (progn

      ;;;--- Something is selected, so convert from string to integer
      (setq sIndex(atoi sStr))

      ;;;--- And get the selected item from the list
      (setq sName(nth sIndex myList))
    )

    ;;;--- Else, nothing is selected
    (progn

      ;;;--- Set the index number to -1
      (setq sIndex -1)

      ;;;--- And set the name of the selected item to nil
      (setq sName nil)
    )

  )
)


Notes:

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.


List_Box  Multiple Choice

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.


PopUp_List

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
  (setq sStr(get_tile "mylist"))

  (if(= sStr "")(alert "No Item was Selected!"))

)


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
    label = "Choice 1";
    key = "choice1";
  }

  : radio_button {       // Second radio button
    label = "Choice 2";
    key = "choice2";
  }

  : radio_button {       // Third radio button
    label = "Choice 3";
    key = "choice3";
  }

  : radio_button {       // Fourth radio button
    label = "Choice 4";
    key = "choice4";
  }

}                        // 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
  ;;;    [ returns "choice1" "choice2" "choice3" or "choice4" ]

  (setq choicesVal(get_tile "choices"))

)

OR

(defun saveVars()

  ;;;--- Get the value of each item
  (setq choice1(atoi(get_tile "choice1"))) 
; 0 = not chosen    1 = chosen  
  (setq choice2(atoi(get_tile "choice2"))) 
; 0 = not chosen    1 = chosen
  (setq choice3(atoi(get_tile "choice3"))) 
; 0 = not chosen    1 = chosen
  (setq choice4(atoi(get_tile "choice4"))) 
; 0 = not chosen    1 = chosen

)


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
    label = "Choice 1";
    key = "choice1";
  }

  : radio_button {       // Second radio button
    label = "Choice 2";
    key = "choice2";
  }

  : radio_button {       // Third radio button
    label = "Choice 3";
    key = "choice3";
  }

  : radio_button {       // Fourth radio button
    label = "Choice 4";
    key = "choice4";
  }

}                        // 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
  ;;;    [ returns "choice1" "choice2" "choice3" or "choice4" ]

  (setq choicesVal(get_tile "choices"))

)

OR

(defun saveVars()

  ;;;--- Get the value of each item
  (setq choice1(atoi(get_tile "choice1"))) 
; 0 = not chosen    1 = chosen  
  (setq choice2(atoi(get_tile "choice2"))) 
; 0 = not chosen    1 = chosen
  (setq choice3(atoi(get_tile "choice3"))) 
; 0 = not chosen    1 = chosen
  (setq choice4(atoi(get_tile "choice4"))) 
; 0 = not chosen    1 = chosen

)


Toggle

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
  (setq tog1Val(atoi(get_tile "tog1")))   ;0 = unchecked   1 = checked

)

 


Ok_Cancel

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" "(done_dialog 1)")

(action_tile "accept" "(saveVars)(done_dialog 2)")

Ahh....finally the SaveVars routine shows up.

3

Nothing to do in the saveVars routine for these buttons.  

Back


AutoLisp DCL Tutorial Home

AutoLisp Home

Home

All questions/complaints/suggestions should be sent to JefferyPSanders.com

Last Updated May 22nd, 2013

Copyright 2002-2013 JefferyPSanders.com. All rights reserved.