Sunday, September 1, 2013

AutoLISP Program For Drawing A Cabinet 4


Getting The Sizes 2


The AutoLISP programs has got two functions for getting the sizes of the cabinet, that we want. These functions are GETSZ and VALUE.


(defun getsz (/ di fl hi ls nr oh th wd wi)
(setq fl 0
wd 600
oh 50
th 25
)
(while (= fl 0)
(setq di (load_dialog "c:/make/cabin.dcl"))
(new_dialog "cabin" di)
(setq wi (dimx_tile "im")
hi (dimy_tile "im")
)
(start_image "im")
(fill_image 0 0 wi hi 0)
(slide_image -100 -100
(+ wi 100)
(+ hi 100)
"c:/make/cabin.sld"
)
(end_image)
(set_tile "wd" (itoa wd))
(set_tile "nr" "2")
(set_tile "oh" (itoa oh))
(set_tile "th" (itoa th))
(mode_tile "wd" 3)
(start_list "nr" 3)
(add_list "3")
(add_list "4")
(add_list "5")
(add_list "6")
(end_list)
(action_tile "accept" "(setq ls (value))
(done_dialog)")
(start_dialog)
(unload_dialog di)
(setq fl (nth 0 ls)
wd (nth 1 ls)
nr (nth 2 ls)
oh (nth 3 ls)
th (nth 4 ls)
)
)
(list wd nr oh th)
)


(defun value (/ fl nr oh th wd)
(setq wd (atoi (get_tile "wd"))
nr (atoi (get_tile "nr"))
oh (atoi (get_tile "oh"))
th (atoi (get_tile "th"))
)
(cond
((= nr 0)
(setq nr 3)
)
((= nr 1)
(setq nr 4)
)
((= nr 2)
(setq nr 5)
)
((= nr 3)
(setq nr 6)
)
)
(if (< wd 400)
(progn
(alert "Minimum width is 400")
(setq fl 0)
)
(setq fl 1)
)
(list fl wd nr oh th)
)


The GETSZ Function


In the GETSZ function we start with setting the base values. Those values are:


fl - flag
wd - width of the cabinet
nr - number of drawers
oh - overhang
th - thickness of the top


You can see what values have been given to the variables. Next we go into a WHILE loop. We stay there as long as the FL variable is 0.


In the WHILE loop we load the DCL file and we display the dialog box. The base values are given to the tiles of the dialog box.


The user can enter values in the edit boxes, When he clicks on the OK button, then the values are evaluated. There is seen what has been entered.


The VALUE Function


That is done in the VALUE function. The value of the popup list is checked with a COND function. See how it is done.


That is important. If the first choice is selected, then the popup list gives back zero. One is given back for the second choice. Etc.


Next there is the value of the width variable checked. If it is smaller than 400, then a warning dialog box is displayed.


In the dialog box is said that the minimum width is 400. The FL variable gets the value zero. The user gets a second chance to enter the width.


If the value of the width is 400 or more, then the FL variable gets the value 1. And there is jumped out of the WHILE loop.


All the values are given back to the GETSZ function.


The DCL File


We need to talk about the DCL file. Here it is:


cabin:dialog
{
label="Cabinet";
:boxed_column
{
:image
{
height=30;
width=80;
key="im";
}
spacer_1;
}
spacer_1;
: boxed_column
{
width = 25;
fixed_width=true;
alignment="centered";
: edit_box
{
key = "wd";
label = "Width:";
edit_width = 5;
initial_focus = true;
}
:popup_list
{
key = "nr";
label = "Drawers:";
edit_width = 1;
value = "";
}
: edit_box
{
key = "oh";
label = "Overhang:";
edit_width = 5;
}
: edit_box
{
key = "th";
label = "Thickness top:";
edit_width = 5;
}
spacer_1;
}
spacer_1;
ok_only;
}


I'm not going to say much about it. I guess it is clear what is done with the DCL file. Tiles are specified in the DCL file.


Next Post



In the next post I'm going to talk about drawing the cabinet. We have all the sizes that we need. So we can draw it.