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.


Friday, August 9, 2013

AutoLISP Program For Drawing A Cabinet 2

Empty Screen


When we draw the cabinet, we want to start with an empty screen. Everything that is on the screen has to be deleted first.


The CLSCR Function


We do that with the CLSCR function. Here it is:


(defun clscr (/ ss)
   (command "zoom" "extents")
   (setq p1 (getvar "vsmin")
            p2 (getvar "vsmax")
   )
   (setq ss (ssget "c" p1 p2))
   (if ss
      (command "erase" "all" "")
   )
)


How The Function Works


This is how the function works. We start with the ZOOM command. We choose the extents option of that command.


The corner points of the screen are stored in the system variables VSMIN and VSMAX. The values go to the P1 and P2 variable.


Next the SSGET function is used. The area between the points P1 and P2 is selected. There is checked whether entities can be found there.


If entities are found there, then the variable SS gets a value. If no entities are found, then the variable SS has got the value nil.


If the variable SS has got a value, then the ERASE command is invoked. All entities are deleted. And we have an empty screen.


The Next Post



In the next post I'm going to talk about entering the sizes of the cabinet. That is done with a dialog box. Wait till the next post.

Saturday, August 3, 2013

AutoLISP Program For Drawing A Cabinet 1

Eleven Posts

Now you'll get an AutoLISP program for drawing a cabinet. I'm going to talk about it in the following eight posts:

1.   Introduction
2.   Clearing The Screen
3.   Getting The Sizes 1
4.   Getting The Sizes 2
5.   Drawing The Cabinet
6.   Drawing The Top
7.   Drawing The Drawers
8.   Drawing The Handles
9.   Setting The Dimension Variables
10. Dimensioning The Drawing
11. The Complete Program

How The AutoLISP Program Works

First let's tell you how the AutoLISP program works. When the program starts a dialog box is displayed. Here is the dialog box.



In the dialog box a picture of the cabinet is displayed. And also is explained where the sizes of the dialog box can be found.

There are three sizes:

1. Width
2. Overhang
3. Thickness top

The user can fill in the sizes. The user can also set how many drawers he wants in the cabinet: three, four, five, or six.

That is important. The minimum width of the cabinet is 400. Suppose the user enters a width that is less than 400.

If so, then the following dialog box is displayed. And the user can enter an different width.



The user has filled in the sizes and suppose he has wants to have a cabinet with three drawers. The cabinet is drawn. This is how it looks:



The Parts

As you can see in the drawing. The following parts have been drawn:

1. The Cabinet
2. The Top
3. The Drawers
4. The Handles
5. The Dimensions

You also find the dimensions in the drawing of the cabinet. The dimensions have been drawn in the drawing of the cabinet.

Next Posts

We are going to talk about the segments of the AutoLISP program that perform the actions. We are also going to talk about getting the sizes.

The actions will be performed by AutoLISP functions. I'm going to talk about them in the next posts of this series.