Writing
GUI Programs in Auto CAD
Mr.
T. Venkatesan, IV year Mechanical Engg., P.E.C.
Auto
CAD is the well known CAD software package among other CAD
soft wares available in the
market. Large and complicated drawings can be drawn using Auto CAD. Auto
CAD is really a boon to Civil and Mechanical engineers. Auto CAD has an
in-built Auto LISP interpreter. Using Auto LISP, we can create application
software involving Auto CAD drawings. As far as application software is
concerned, it should contain a good Graphics User Interface (GUI). But
Auto LISP does not support GUI functions. So, Auto DESK, the creator of
Auto CAD included "Dialog Control Language" (DCL) along with Auto LISP.
Dialog Control Language (DCL) :
Using Dialog Control Language (DCL), we can include GUI
components like message box, text
field, command button, radio button, check box, dialog box etc. The structure
of DCL is somewhat similar to C language. The program written in DCL is
not a stand-alone program. It should be linked with Auto LISP and then
interpreted. The program structure of DCL is same for both DOS based and
WINDOWS based Auto CAD. But the appearance of GUI depends upon the platform.
The extensions for DCL program and Auto LISP are .dcl and .lsp respectively.
Message Box Example :
Let us now try one example program and learn how to link, execute with
AUTO LISP. Now, we
are going to write one program in DCL that displays a message box "DCL
is a language for user interface programming for Auto CAD" along with an
"OK" button.
Type the following program in any text editor or use "Edit" command in
the command prompt
of Auto CAD. Save the file as "example.dcl".
Program :
example : dialog
{
label : "First DCL program";
: text
{
label : "DCL is a language for";
}
: text {
label : "user - interface programming";
}
: text {
label : "for Auto CAD";
}
: button {
key = "accept";
label = "OK";
is_default = true;
fixed_width = true;
alignment = centered;
}
}
To run this program, type (load "first.lsp") in Auto CAD command prompt.
If there is no error
in the program, "loaded" message will appear. Then type the name of the
function, i.e., "dialog" in the command prompt. The message box you created
using DCL language will appear with an "OK" button. On clicking the "OK"
button, it disappears. One important thing to be noted here is that both
the .dcl and .lsp program files should be in the same directory.
Let me now analyze the program. The line "example : dialog" represents
that this is a program for
dialog box and that dialog box is named as "example". The program coding
present in-between the two braces ‘{‘ and ‘}’ represents how the dialog
box should appear. "label" gives the title of the dialog box. In our case,
"First DCL Program" is the title.
Similarly, ": text" is used to represent what the text of the dialog box
should contain. Here, I have
given three ": text" to give three lines of text. Similarly, ": button"
is used to design a button. In our example, I have given "OK" button alone.
You may also give more than one button like "OK", "CANCEL", "HELP" etc.
"label" represents the caption of the button. In our example "OK".
" is_default" indicates the default button, i.e., if the user presses any
key, then it will be taken that the user selects "OK" button.
"fixed_width" fixes the size of the button as that of the caption given
by us.
"alignment" indicates how the caption appears in the button whether centered
or right_ justified or left_ justified.
Dialog Box Example :
Type and save the following program as "biodata.dcl".
input : dialog
{
label : "Biodata";
: edit_box
{
label = "Enter your name";
key = "name";
edit_width = 20;
}
: edit_box
{
label = "Enter your age";
key = "age";
edit_width = 3;
}
:edit_box
{
label = "Enter your sex";
key = "sex";
edit_width = 6;
}
: button {
label = "OK";
key = "accept";
is_default = true;
fixed_width = true;
alignment = centered;
}
}
Let us now see the Auto LISP program that executes this biodata.dcl program.
Save the following
Auto LISP program as "data.lsp".
(define c:biodata()
(setq dcl_id(load_dialog"biodata.dcl"))
(if (not(new_dialog "input" dcl_id))
(exit)
)
(action_tile "name" "(setq name $value)")
(action_tile "age" "(setq age $value)")
(action_tile "sex" "(setq sex $value)")
(start_dialog)
)
To execute "data.lsp" program, type the following in the command prompt
of Auto CAD, i.e.,
(load "data.lsp") and a message "loaded" will be displayed provided there
is no error in the program. Now type "biodata" ,i.e., the name of the function
in the command prompt to run this program.
The "data.lsp" program uses "biodata.dcl" program.Let us now analyze this
program. In
"data.lsp", "action_tile" command assigns the string present in the key
"name" to the variable "name". Similarly, age and sex are assigned to the
age and sex variables respectively.
The command new to us in the program is ":edit_box". This "edit_box" is
used to create
a text box which is used to get the input from the user during runtime.
"label" is the command which is used to give the caption for the text box.
The user's response is stored in the key variable. In our case, the key
variables are name
age and sex.
"edit_width" is used to determine the size of the text box which is the
size of the input
string. Our dialog box example program contains three text boxes and one
"OK" button. One important point to be noted here is that like C language,
every line of a DCL program ends with a semi-colon.
Send your queries to :t_vengatesant
@ hotmail.com
Previous Pages:
CTI
- It Happened in P.E.C.
FACE
TO FACE a interview with Dr. S.V. Narayanan.
WINDOWS
REGISTRY
VIRUSES
OF INDIA
Next page:
Letters
to The Editor.
The Cybyrus Team
Created by S.MANICANDAN and S.KARHTIK
(III year CSE, 1996 - 2000 batch)
Last Updated Date : 15th September 1998.