Sie sind auf Seite 1von 4

getpoiont

Lesson 1 setq defun

command

at the command prompt, type : line computer response: from point pick a point on the screen computer response: to point pick a point on the screen computer response: to point press Enter key Above are the steps in AutoCAD to use the Aline@ command. getpoint an AutoLisp function to request an input of a point. getpoint also echos a preassigned message.

In order to understand the use of getpoint and setq, at the command prompt, type : (getpoint "Pick 1st point") computer response: Pick 1st point pick a point on the screen setq an AutoLisp function to assign variables in AutoLisp. In order to assign a point to a variable name for later retrieval at the command prompt, type: (setq A (getpoint "Pick 1st point")) computer response: Pick 1st point pick a point on the screen A point was picked, and the use of setq allows later retrieval of the point. In order to assure you did assign the point to the variable name A at the command prompt, type: !A the computer should print the co-ordinates of the point you picked last. The factorial symbol, ! , is used to get the value of any defined AutoLisp variables. At the command prompt, type: (setq B (getpoint "Pick 2nd point")) computer response: Pick 2nd point 1-- 1

pick a point on the screen The AutoLisp function command is used to call up a standard AutoCAD command. It should precede a standard AutoCAD command enclosed by a pair of double quotation marks. In order to see how this function works, at the command prompt, type:
(command "line" A B "")

press Enter key A line connecting two points, A and B, is drawn. The start point and end point of the line will be point A and point B respectively. What you have done was to draw a line by means of AutoLisp function. AutoLisp could be executed line by line, just like what you have done, but a formal AutoLisp routine to draw a line should be:
(defun c:line1 () (setq A (getpoint "Pick 1st point")) (setq B (getpoint "Pick 2nd point")) (command "line" A B "") )

Use Note Pad, Word Pad, or any other available window version text-editor and type:
(defun c:line1 () (setq A (getpoint "Pick 1st point")) (setq B (getpoint "Pick 2nd point")) (command "line" A B "") )

When done, save the file as A:LINE1.LSP The file must be saved as text file.

Explanation of the lines typed: 1-- 2

(defun c: line1 () )

is a standard way to start an AutoLisp programme. means to define a customized command; nothing to do with drive C: the customized command will be known as line1 a pair of bracket means there will be variables in the programme and the variables will stay in the memory after execution of the AutoLisp routine. this is the closing bracket for the whole programme.

Minimize the text editor and return to AutoCAD,

Now is the time to load and run the AutoLisp routine, LINE1.LSP, you just typed. at the command prompt type: computer will response:
(load "A:line1")

c:line1

now LINE1 becomes your customized command to draw a line. Whenever you want to use it to draw a line you could type LINE1

Improvement of above AutoLisp routine:Maximize the text editor and modify the file, line1.lsp to read:
(defun c:line1 () (setq A (getpoint "Pick 1st point")) (setq B (getpoint "Pick 2nd point" A)) (command "line" A B "") )

This modification will produce an elastic band originating from point A. Load the AutoLisp file again. Execute the file and appreciate the difference. LINE1.LSP, though not a very practical file, does illustrate the principles of input and output in an AutoLisp programme. The best way to learn AutoLisp is by doing exercises. By applying the AutoLisp functions learned, you should be able to do the following tutorial. Tutorial for Lesson 1:1-- 3

1.

Write an AutoLisp routine which will ask the user to pick 5 points and then draw a 5 - vertice star. (STAR5.LSP) Write an AutoLisp routine which will ask the user to pick 20 points and then the first picked point will joint all subsequently picked points. (BUSH.LSP)

2.

1-- 4

Das könnte Ihnen auch gefallen