-
Using Functions
-
Getdist- Pauses for user input of a distance
-
Getangle or Getorient - Pauses for user input of an angle
Using Functions
Let's see how this new version of the Box drawing program works.
1. Open a new AutoLISP file called box1.lsp.
2. Enter the above three functions, Getinfo, Procinfo, and output, along with the new box program.
3. Open a new AutoCAD file and load the Box1.lsp file.
4. Run the BOX1 program. You will see that it acts no differently from the first box1 program.
Reusing Functions
You have seen that by breaking the box program into independent functions, you can add other functions to your program to alter the way the program works. In the following section, you will create two more programs, one to draw a 3D rectangle, and one to draw a wedge, using those same functions from the box program.
Creating an 3D Box program
(defun C:3DBOX (/ pt1 pt2 pt3 pt4 h)
(getinfo)
(setq h (getreal "Enter height of box: "))
(procinfo)
(output)
(command "change" "L" "" "P" "th" h ""
"3dface" pt1 pt2 pt3 pt4 "" "3dface"
".xy" pt1 h ".xy" pt2 h ".xy" pt3 h ".xy" pt4 h "")
)
In the following exercise, you will add the 3D box program to the Box1.lsp file then run 3DBOX.
-
Exit AutoCAD temporarily either by using the AutoCAD Shell command or by using the End command to exit AutoCAD entirely.
-
Open the box1.lsp file again and add the program listed above to the file. download code.
-
Load Box1.lsp again. If you had to Exit AutoCAD to edit Box1.lsp.
-
Start the C:3DBOX program by entering 3dbox at the command prompt.
-
At the Pick first corner prompt, pick a point near the coordinate 2,3.
-
At the Pick opposite corner prompt, move the cursor until the coordinate readout lists 7.0000,5.0000 then pick that point.
-
At the Enter height prompt, enter 6. A box appears.
-
Issue the Vpoint command and at the prompt:
-
Enter -1,-1,1.Now you can see that the box is actually a 3d box.
-
Issue the Hide command. The box appears as a solid object.
pt (Optional)
A 2D or 3D point to be used as the base point in the current UCS. If pt is provided, the user is prompted for the second point. you can also provide value by keyboard too.
msg (Optional)
A string to be displayed to prompt the user. If no string is supplied, AutoCAD does not display a message.
Return Values
(getangle [pt] [msg])
pt (Optional)
A 2D base point in the current UCS. If pt is provided, the user is prompted for the second point. you can also provide value by keyboard too.
msg (Optional)
A string to be displayed to prompt the user. If no string is supplied, AutoCAD does not display a message.
Return Values
A rubber-banding line appears from the coordinate 3,3. now Pick a point other than coordinate 2,5. The angle from pt1 to second point is assigned to ang1.
To get the value of ang1, enter: