Dialogue Boxes - Step by Step - Page I.
To download source coding Click Here.
This tutorial will take you through all the steps of designing an
AutoLISP routine with, a Dialogue Box Interface.
It will guide you through the coding of the DCL file, to the retrieval of
the data from the Dialogue Box.
The dialogue box we will be designing will consist of the following :
- A Radio Column consisting of 6 Radio Buttons to allow the user to
choose the type of bolt.
- A Drop Down List Box for the size of the bolt.
- An Edit Box for the length of the slot.
- A Slider, also for the length of the slot.
- A Boxed Row containing 2 Toggle Buttons.
- An Edit Box to enter Notes.
- An OK/Cancel pre-defined set of tiles.
- An Image Tile.
- A Paragraph tile containing Text.
Let's start with a very simple Dialogue Box containing simply, an OK
button and a cancel button.
The dialogue box will look like this :
Let's look at the DCL coding for this dialogue :
samp1 : dialog { //dialog name
label = "Structural Holes" ; //give it a label
ok_cancel ; //predifined OK/Cancel
} //end dialog
Note the use of the predefined OK/Cancel tile. This is a standard tile set
as defined in the AutoCAD Base. DCL File. (You can refer to the AutoCAD
Customization Manual for more examples.)
Now for the AutoLISP coding that calls the dialogue and handles each
tile :
(defun C:samp1 () ;define function
(setq dcl_id (load_dialog "samp1.dcl")) ;load dialog
(if (not (new_dialog "samp1" dcl_id) ;test for dialog
);not
(exit) ;exit if no dialog
);if
(action_tile
"cancel" ;if cancel button pressed
"(done_dialog) (setq userclick nil)" ;close dialog, set flag
);action_tile
(action_tile
"accept" ;if O.K. pressed
" (done_dialog)(setq userclick T))" ;close dialog, set flag
);action tile
(start_dialog) ;start dialog
(unload_dialog dcl_id) ;unload
(princ)
);defun C:samp
(princ)
Let's add a paragraph of text to the dialogue. Only the DCL file changes
here, the AutoLISP coding remains the same except for the function name.
NOTE : //* preceding the comments denotes new coding :
The revised DCL coding looks like this :
samp2 : dialog { //dialog name
label = "Structural Holes" ; //give it a label
ok_cancel ; //predifined OK/Cancel
: paragraph { //*define paragraph
: text_part { //*define text
label = "Designed and Created"; //*give it some text
} //*end text
: text_part { //*define more text
label = "by Kenny Ramage"; //*some more text
} //*end text
} //*end paragraph
} //end dialog
And the coding remains the same except for name change :
(defun C:samp2 () ;define function
(setq dcl_id (load_dialog "samp2.dcl")) ;load dialog
(if (not (new_dialog "samp2" dcl_id) ;test for dialog
);not
(exit) ;exit if no dialog
);if
(action_tile
"cancel" ;if cancel button pressed
"(done_dialog) (setq userclick nil)" ;close dialog, set flag
);action_tile
(action_tile
"accept" ;if O.K. pressed
" (done_dialog)(setq userclick T))" ;close dialog, set flag
);action tile
(start_dialog) ;start dialog
(unload_dialog dcl_id) ;unload
(princ)
);defun C:samp
(princ)
Now we will add an image tile to make it look nice :
The DCL coding :
samp3 : dialog { //dialog name
label = "Structural Holes" ; //give it a label
ok_cancel ; //predifined OK/Cancel
: row { //define row
: image { //*define image tile
key = "im" ; //*give it a name
height = 1.0 ; //*and a height
width = 1.0 ; //*and now a width
} //*end image
: paragraph { //define paragraph
: text_part { //define text
label = "Designed and Created"; //give it some text
} //end text
: text_part { //define more text
label = "by Kenny Ramage"; //some more text
} //end text
} //end paragraph
} //end row
} //end dialog
Because we haven't given the image tile a fixed height or a fixed width,
it will expand or contract to suit the available space. Now the AutoLISP
coding :
(defun C:samp3 () ;define function
(setq dcl_id (load_dialog "samp3.dcl")) ;load dialog
(if (not (new_dialog "samp3" dcl_id) ;test for dialog
);not
(exit) ;exit if no dialog
);if
(setq w (dimx_tile "im") ;*get image tile width
h (dimy_tile "im") ;*get image tile height
);setq
(start_image "im") ;*start the image
(fill_image 0 0 w h 5) ;*fill it with blue
(end_image) ;*end image
(action_tile
"cancel" ;if cancel button pressed
"(done_dialog) (setq userclick nil)" ;close dialog, set flag
);action_tile
(action_tile
"accept" ;if O.K. pressed
" (done_dialog)(setq userclick T))" ;close dialog, set flag
);action tile
(start_dialog) ;start dialog
(unload_dialog dcl_id) ;unload
(princ)
);defun C:samp
(princ)
Note the following coding :
(setq w (dimx_tile "im") ;*get image tile width
h (dimy_tile "im") ;*get image tile height
This retrieves the width and height of the image tile and allocates them
to variables w and h respectively.
The next code fragment uses these variables to "draw" the image
tile.
The number "5" denotes the AutoCAD colour "Blue" :
(start_image "im") ;*start the image
(fill_image 0 0 w h 5) ;*fill it with blue
(end_image) ;*end image
|