Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
George Omura. Lisp programing tutorial for AutoCAD customization / 620.0.The ABC's of AutoLISP - Omura, George.pdf
Скачиваний:
140
Добавлен:
02.05.2014
Размер:
1.55 Mб
Скачать

The ABC’s of AutoLISP by George Omura

Chapter 6: Working With Geometry

Introduction

How to Find Angles and Distances

Understanding the Angle, Distance, and Polar Function

Using Trigonometry to Solve a Problem

Gathering Information

Finding Points Using Trigonometry

Conclusion

Introduction

It is inevitable that your work with AutoLISP will involve some geometric manipulations. With the box program in chapter 2, you have already created a program that derives new point locations based on user input. There, you learned how to take coordinate lists apart, then re-assemble them to produce a new coordinate. In this chapter, you will be introduced to other AutoLISP functions that will help you determine locations in your drawings coordinate system and in the process, you will review some basic trigonometry.

How to find Angles and Distances

In chapter 4, you learned how to prompt the user for angles and distances. At time, however, you will want to find angles and distances based on the location of existing point variables rather than relying on user input every time you need to find an angle.

Suppose you want to find a way to break two parallel lines between two points in a manner similar to the standard AutoCAD break command. In addition, you would like this function to join the ends of the two broken portions of each line to form an opening. Figure 6.1 shows a drawing of the process along with a description of what must occur. This drawing can be developed into pseudocode for your program. A function similar to this is commonly used in architectural drawings to place an opening in a wall.

112

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

Figure 6.1: Sketch of the parallel line break program

In Chapter 3, we discussed the importance of designing your program to be simple to use. This program is designed

113

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

to obtain the information needed to perform its task using the minimum of user input. Since it is similar to the break command, it also tries to mimic the break program to some degree so the user feels comfortable with it. As you read through this section, pay special attention to the way information is gathered and used to accomplish the final result.

Open an AutoLISP file called Break2.lsp and copy the program in figure 6.2. Open a new AutoCAD file called Chapt6. Draw a line from point 2,4 to 12,4 then offset that line a distance of 0.25 units. Your screen should look like figure 6.3.

;Program

to break 2 parallel lines -- Break2.lsp

 

(defun c:break2 (/ pt1 pt2 pt3 pt4 pt0 ang1 dst1)

 

(setvar "osmode" 512)

;near osnap mode

(setq

pt1 (getpoint "\nSelect object: "))

;get first break point

(setq

pt2 (getpoint pt1 "\nEnter second point: "))

;get second break point

(setvar "osmode" 128)

;perpend osnap mode

(Setq

pt3 (getpoint pt1 "\nSelect parallel line: "));get 2nd line

(Setvar "osmode" 0)

;no osnap mode

(setq

ang1 (angle pt1 pt3))

;find angle btwn lines

(setq

dst1 (distance pt1 pt3))

;find dist. btwn lines

(setq

pt4 (polar pt2 ang1 dst1))

;derive pt4 on 2nd line

(command

 

 

"break" pt1 pt2

;break 1st line

 

"break" pt3 pt4

;break 2nd line

 

"line" pt1 pt3 ""

;close ends of lines

 

"line" pt2 pt4 ""

 

)

 

 

)

 

 

 

 

 

 

 

 

Figure 6.2: The parallel line break program

114

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

Figure 6.3: Two parallel lines drawn

1.Load the Break2.lsp file and enter break2 at the Command prompt.

2.At the prompt:

Select object:

The osnap cursor appears. Pick the lowermost line near coordinate 5,4. 3. At the next prompt:

Enter second point:

Pick the lowermost line again near coordinate 10,4. 4. Finally, at the prompt:

Select parallel line:

115

Copyright © 2001 George Omura,,World rights reserved