
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
|
|
The AutoLisp Tutorial - DCL Dialog Control Language - Part 2 Part 2 - Edit_Box Let's build a working DCL file showing us exactly how to handle edit boxes. We will build a DCL file containing two edit boxes plus a Okay and Cancel button. The information in the two edit boxes will be displayed after selecting the Okay button. Layout thoughts: I will place the edit boxes in a column, (stacked on top of each other). Then I'll put the Okay and Cancel buttons at the bottom in a row. 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. SAMPLE2 : dialog { } Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE2.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:SAMPLE2() Right click and copy the above. Open NotePad and paste it. Save the file as SAMPLE2.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 "sample2") and press enter You should see this C:Sample2 Now type Sample2 and press enter. If everything went according to plan you should see this on your screen:
Looking good so far. We need to add the SaveVars function to save the strings in the edit boxes when the Okay button is pressed. Look at the blue text in the Sample2.lsp program above. The edit box for the name needs to be a string. Dialog boxes return strings, so we do not need to modify it. All we have to do is use the get_tile function. (setq userName(get_tile "username"))
(setq userAge( atoi
(get_tile "userage"))) If we needed to convert to an Real number we would use DISTOF function instead of the ATOI function. Our SaveVars routine would look like this: (defun saveVars() Our program would now look like this: (defun saveVars() (defun C:SAMPLE2() Last item. We need to replace the line in the program: (princ "\n The user pressed Okay!") with something to modify and display the userName and userAge data. Let's do something simple. We will find out how many days old this person is. ;;;--- If the user pressed
the Okay button
;;;--- Multiply the users age x 365 to get the number of days.
;;;--- Display the results 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:SAMPLE2() ] 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 March 31st, 2006 Copyright 2002-2008 JefferyPSanders.com. All rights reserved. |