Welcome to the Southern African Autolisp Website.
You are Visitor Number
|
| Page I. | Home. | Page III. | Page IV. |
(defun testline () ;define the function (setq a (getpoint "\nEnter First Point : ")) ;get the first point (setq b (getpoint "\nEnter Second Point : ")) ;get the second point (command "Line" a b "") ;draw the line ) ;end defun
Now, save this file as "testline.lsp" remembering, to save it as a
ASCII Text file and ensuring that it is saved in a directory in your
AutoCAD's search path. Now open AutoCAD and type this :
(load "testline")
This will load the function into memory. (Did you notice that you do not
have to stipulate the "lsp" extension?)
Now type this :
(testline)
Your function should now run.
Let's edit this routine so that it acts like a standard AutoCAD command :
(defun c:testline () ;define the function (setq a (getpoint "\nEnter First Point : ")) ;get the first point (setq b (getpoint "\nEnter Second Point : ")) ;get the second point (command "Line" a b "") ;draw the line ) ;end defun
By preceding the function name with c: we do not have to enclose the
name with brackets when running. Re-load the function and run it again.
(load "testline") testline
Much better, Hey.
We do have one problem though. Did you notice that when we loaded the routine,
an annoying "nil" kept on popping up. We also got the same "nil" returned
to us when we ran the routine. To suppress this "nil" when loading or
running, we can use the (princ) function. Here's what your routine would
look like :
(defun c:testline ()
;define the function
(setq a (getpoint "\nEnter First Point : "))
;get the first point
(setq b (getpoint "\nEnter Second Point : "))
;get the second point
(command "Line" a b "")
;draw the line
(princ)
;clean running
) ;end defun
(princ)
;clean loading
For more details on the (defun) function, refer to The AfraLisp Tutorial :
And for a more detailed expanation of loading AutoLisp routines, refer to the AfraLisp tutorial :
The values that we need to retrieve from the user are as follows :
Insertion Point ip Length of Beam lb Height of Beam hb Flange Thickness wt End Plate Thickness ep Length of Notch nl Depth of Notch nd
Let's write a routine to retrieve these values first.
(defun c:testbeam () ;define the function ;******************************************************** ;Get User Inputs (setq lb (getdist "\nLength of Beam : ")) ;get the length of the beam (setq hb (getdist "\nHeight of Beam : ")) ;get the height of the beam (setq wt (getdist "\nFlange Thickness : ")) ;get the thickness of the flange (setq ep (getdist "\nEnd Plate Thickness : ")) ;get the thickness of the end plate (setq nl (getdist "\nLength of Notch : ")) ;get the length of notch (setq nd (getdist "\nDepth of Notch : ")) ;get the depth of the notch ;End of User Inputs ;********************************************************* ;Get Insertion Point (setq ip (getpoint "\nInsertion Point : ")) ;get the insertion point ;******************************************************** (princ) ;finish cleanly ) ;end of defun ;********************************************************** (princ) ;load cleanly ;**********************************************************
Load and run the routine. You will be prompted for all the values
listed above. Enter some numbers and then check the value of all the
variables by preceeding the value names with "!" (e.g. !ip).
| Page I. | Home. | Page III. | Page IV. |