jpsheader.jpg (29354 bytes)

Back to DCL Tutorial Homepage

Back to AutoLisp Homepage

Back to























The AutoLisp Tutorial - DCL

Dialog Control Language - List

List and how to handle them.

   List_box and popup_list handle a list of items in basically the same manner.  You have to load your list into the list box and at some point you have to decide which item or items were selected.  In the "Saving data from a dialog box" I cover how to find the selected items from a list_box and a popup_list.   How do we get the list inside the list_box?  That is what we need to cover in this section.  So let's get started.

  If you looked at the previous sections you know the AutoLisp and DCL basic model.  Let's get a copy of that in this section so we can look at it.  I will replace the edit_box with a list_box control and add the code to handle the list.   The list handling code is shown in the "Saving data from a dialog box" section of this tutorial. 

   I will show the revised and new code in red below.  All of the black code is unchanged from the Basic Model and the instructions from the "list_box multiple selection" area of the "Saving data from a Dialog box" page.

The Basic Revised Model

The DCL File:

EXAMPLE : dialog {
          label = "EXAMPLE.lsp";         
// Puts a label on the dialog box
          : column {
            : row {
              : boxed_column {
               : list_box {                  // I replaced the edit_box with a list_box.
                  label ="Choose Items";
                  key = "mylist";
                  height = 15;
                  width = 25;
                  multiple_select = true; 
// Multiple selection is on
                  fixed_width_font = true;
// Fixed Width Font is on
                  value = "0";

            : row {
              : boxed_row {
                : button {
                  key = "accept";
                  label = " Okay ";
                  is_default = true;
                : button {
                  key = "cancel";
                  label = " Cancel ";
                  is_default = false;
                  is_cancel = true;

The AutoLisp File:

;;;--- EXAMPLE.lsp

;;;--- I replaced the saveVars routine with the one from the "Save data from a list" section of this tutorial.
;;;        I also changed the things marked in red.

(defun saveVars(/ readlist count item)

  ;;;--- Notice the "mylist" is the action key associated with the DCL file and
  ;;;    the myList is the variable for the list built below.
  ;;;--- Setup a list to hold the selected items
  (setq retList(list))

  ;;;--- Save the list setting
  (setq readlist(get_tile "mylist"))

  ;;;--- 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 myList))))
        (/= " " (substr readlist count 1))
        (/= ""   (substr readlist count 1))
      (setq count (1+ count))
    (setq readlist (substr readlist count))

(defun C:EXAMPLE()

  ;;;--- I need to build a list of data
  (setq myList(list "1" "2" "3" "4" "5" "6" "7" "8"))

  ;;;--- Load the dcl file from disk into memory
  (if(not(setq dcl_id (load_dialog "EXAMPLE.dcl")))
      (alert "The DCL file could not be loaded!")
    ;;;--- Else, the DCL file was loaded into memory

      ;;;--- Load the dialog definition inside the DCL file
      (if (not (new_dialog "EXAMPLE" dcl_id))
          (alert "The DCL definition could not be found inside the DCL file!")

        ;;;--- Else, the dialog definition loaded

          ;;;--- Here, I add the data to the list_box control
          ;;;    I do this after the new_dialog call and before the action_tiles.
  (start_list "mylist" 3)
          (mapcar 'add_list myList)

          ;;;--- Notice the "mylist" is the action key associated with the DCL file and
          ;;;    the myList is the variable for the list built above.

          ;;;--- If an action event occurs, do this function
          (action_tile "cancel" "(done_dialog 1)")
          (action_tile "accept" "(saveVars)(done_dialog 2)")

          ;;;--- Display the dialog box
          (setq ddiag(start_dialog))

          ;;;--- If the cancel button was pressed - display message
          (if (= ddiag 1)
            (princ "\n \n ...EXAMPLE Cancelled. \n ")

          ;;;--- If the "Okay" button was pressed
          (if (= ddiag 2)

            ;;;--- Here, I decide what to do with my data
            ;;;    I'm going to print each selected item on the command line.
     (foreach a retList
              (princ "\n")(princ a)

  ;;;--- Suppress the last echo for a clean exit


  So, in order to display a list in a dialog box, you must first build the list.   Then use the start_list, add_list, and end_list functions just after the new_dialog call and before the action_tiles.  This is the same for both a list_box and a popup_list. 


AutoLisp DCL Tutorial Home

AutoLisp Home


All questions/complaints/suggestions should be sent to

Last Updated May 22nd, 2013

Copyright 2002-2013 All rights reserved.