Friday, August 16, 2013

AutoLISP Program For Drawing A Cabinet 3


Getting The Sizes 1


For drawing a cabinet we need to have the sizes. We need to know:


- What is the width of the cabinet?
- What is the number of drawers?
- What is the size of the overhang?
- What is the thickness of the top?




In the previous post I showed you the dialog box that is used for the the input of the sizes. See the area that is concerned.


The DCL File


We need a DCL file in which the dialog box is specified. This is how the DCL file for drawing a cabinet looks.


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;
}

Two AutoLISP Functions

We have two functions that deal with the dialog box. The first function is for opening the dialog box. The second one is for checking.


Here are both functions:


(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)
)


Next Post


You will get a full explanation of the DCL file and the AutoLISP functions in the next post of this series.