
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
|
|
The AutoLisp Tutorial - DCL Dialog Control Language - Part 1 Part 1 - Buttons Let's build a working DCL file showing us exactly how to handle buttons. We will build a DCL file containing three buttons plus a Close [ Cancel ] button. Each of the three buttons will display a message when pressed. Layout thoughts: I will place the buttons in a column, (stacked on top of each other). Then I'll put the Close button at the bottom on a row of it's own. So...I'll need something like this: : column { Let's copy in the code for the header and all of the controls above. I'll show them in red. Notice the key names and labels had to be changed. SAMPLE1 : dialog { } Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE1.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:SAMPLE1() ;;;--- Unload the dialog box I removed several lines from the model. I took out the part that checked to see if we hit the Cancel or Okay buttons. We don't need either in this program. I also removed the action tile for the okay button and removed "(setq ddiag 1)" from the cancel button. Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE1.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 "sample1") and press enter You should see this C:Sample1 Now type Sample1 and press enter. If everything went according to plan you should see this on your screen:
The buttons do not work yet. Except for the close button. It should work fine. We need to add the function to print three different messages when the user presses each button. Let's send a parameter to the function to decide which message to display. If the parameter equals 1 we will print the first message. If 2 then print the second message. If 3 print the third message. Something like this: (defun doButton(a) Now we need to add the action calls for each of the buttons: (action_tile "but1"
"(doButton 1)") This will send a parameter of 1,2, or 3 to the doButton function depending on which button is pressed. Let's add the doButton function and the action calls to the autolisp program. It should look like this: (defun doButton(a) 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:SAMPLE1() ] 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. |