
Back to AutoLisp Tutorial Homepage
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
D I A L O G
C O N T R O L
|
|
The AutoLisp Tutorial - DCL Dialog Control Language - Part 4 Part 4 - PopUp_List Let's build a working DCL file showing us exactly how to handle popup list. We will build a DCL file containing two pop_up list plus an Okay and Cancel button. The selected items will be displayed on the screen after the user presses the Okay button. Layout thoughts: I will place the popup_list in a row, (side by side). 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. SAMPLE4 : dialog { } Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE4.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:SAMPLE4() Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE4.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 "sample4") and press enter You should see this C:Sample4 Now type Sample4 and press enter. If everything went according to plan you should see this on your screen:
Looks good but, there is nothing to choose. Let's add some data to the popup list boxes. We will need two list. We will call the list for the first popup list box myList1 and the second myList2. (setq myList1(list "Electrical" "Structural" "Plumbing" "Foundation")) (setq myList2(list "Plastic" "Steel" "Aluminum" "Concrete")) Alrighty then, we have our list built. All we have to do is put them in the dialog box. We will use the start_list, add_list, and end_list functions. Start_list tells DCL which popup list box we are going to edit. The identification is made by using the popup list box KEY. The first popup list box has a key of "mylist1" and the second has a key of "mylist2". So the start_list function would look like this: (start_list "mylist1" 3) ; The 3 means we want to delete the old contents and start new. Next we use the add_list function to tell DCL which list to put in the popup list box. We use the mapcar function to apply add_list to each member in the list. Our list for the first popup list box is named myList1. So... (mapcar 'add_list myList1) Finally we use the end_list function to tell DCL to display the new contents because we are through editing the popup list box. (end_list) To look at it all together: (start_list "mylist1"
3) (start_list "mylist2"
3)
Let's add all of this to the AutoLisp program and see what it looks like. (defun C:SAMPLE4() (setq myList1(list "Electrical" "Structural" "Plumbing" "Foundation"))
;;;--- Load the dcl file (start_list "mylist1" 3) (start_list "mylist2"
3) ;;;--- If an action event occurs, do this
function Notice the location of the red lines. We create the list before loading the dialog box. We add the list to the dialog box after it is loaded with new_dialog and before the action_tile statements. This is the order you should use. Looking good so far. We need to add the SaveVars function to save the selected items from the popup list boxes when the Okay button is pressed. Look at the blue text in the Sample4.lsp program above. Let's steal the saveVars routine from the popup list box control on the "Saving data from the dialog box" page of this tutorial and modify it. I'll show the modifications in red.
(defun saveVars() ;;;--- Get the selected item from the first list ;;;--- Make sure something was selected...
Wow! That was easy. Wait a minute, we have two pop_up list boxes. We will have to create a function out of this or simply copy this and do it twice. For now, let's just do it twice. Our program would now look like this:
(defun saveVars() ;;;--- Get the selected item from the first list ;;;--- Make sure something was selected...
;;;--- Get the selected item from the second list ;;;--- Make sure something was selected...
(defun C:SAMPLE4() (setq myList1(list "Electrical"
"Structural" "Plumbing" "Foundation"))
;;;--- Load the dcl file (start_list "mylist1"
4) (start_list "mylist2"
4) ;;;--- If an action event occurs, do this
function Last item. We need to replace the line in the program: (princ "\n The user pressed Okay!") with something to modify and display the selected items. Let's do something simple. We will tell the user what was selected out of each popup list.. ;;;--- If the user
pressed the Okay button
;;;--- Inform the user of his selection from the first list
;;;--- Inform the user of his selections from the second list Add the above to the 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:SAMPLE4() ] 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 JefferyPSanders.com Last Updated January 28th, 2006 Copyright 2002-2008 JefferyPSanders.com. All rights reserved. |