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

The ABC’s of AutoLISP by George Omura

Functions Useful in Geometric Transformations

The majority of your graphic problems can be solved with the basic trigonometric functons used in the Cutcr program. But AutoLISP provides the tools to solve even th emost arcane trigonometric problems. This section shows the functions you are most likely to use in situations that require geometric manipulations.

Trans

Trans translates a coordinate or displacement from one user coordinate system to another. The first argument is a point of reference. The second argument is a code indicating which coordinate system the point is expressed in. The third argument is a code indicating which coordinate system the point is to be translated to. An optional fourth True/nil argument can be included. If this fourth argument evaluates to True or non-nil, then the first argument will be treated as a displacement rather than a point value. The following are the codes for the second and third arguments.

Code Coordinate System

0World Coordinate System

1Current User Coordinate System

2Coordinate system of the current view plane Trans returns a coordinate or displacement list.

The syntax for Trans is

(trans [coordinage_list] [UCS_code] [optionalT/nil] )

Atan

Atan returns the arctangent in radians of its first argument. If the argument is negative, then the value returned will be negative. If two arguments are supplied, then Atan returns a the arctangent of the first argument divided by the second argument.

The syntax for Atan is

(atan [number] [optional_2nd_number])

Inters

Inters returns a coordinate list of the intersection of two vectors. The first two arguments to inters are the endpoints of one vector while the third and fourth arguments define the other vector. If an

135

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

optional fifth agrument is present and evaluates to nil, then Inters will attempt to locate an intersection point of the two vectors regardless of whether the intersection falls between the specified points or not.

The syntax for Inters is

(inters [point point point point] [optional_T/nil])

Sin

Sine returns the sine of an angle as a real number. The angle must be expressed in radians.

The syntax for Sine is

(sin [angle])

Cos

Cos returns the Cosine of an angle as a real number. The angle must be expressed in radians.

The syntax for Cos is

(cos [angle])

Conclusion

The majority of your graphic problems can be solved using the basic trigonometric functions shown in this sample program. But AutoLISP provides the tools to solve even the most arcane Trigonometric problems. If you find you need to use these math trig functions, consider making liberal use of a sketch pad or for that matter, AutoCAD itself to document your program. You may want to re-use or modify programs such as the previous example and if you don't have some graphic documentation recording how it works, you can have a difficult time understanding why you wrote your program as you did.

136

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

137

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

Chapter 7: Working with Text

Introduction

Working With String Data Types

Searching for strings

How to Convert Numbers to Strings and Back

Converting a Number to a String

Converting Other Data Types

How to Read ASCII Text Files

Using a File Import Program

Writing ASCII Files to Disk

Using a Text Export Program

Conclusion

Introduction

If you have ever had to edit large amounts of text in a drawing, you have encountered one of AutoCAD's most frustrating limitations. While AutoCAD's text handling capabilities is one of it's strong points, it still leaves much to be desired where editing text is concerned. Fortunately AutoLISP can be of great help where text is concerned. In this chapter, you will look at the many functions that AutoLISP offers in the way of text or string manipulation. You will also look at how textural information can be store and retrieved from a file on disk and how data can be converted to and from string data types.

Working With String Data Types

In earlier versions of AutoCAD, editing text was a tedious task. You have to use the Change command to select a text line, then press return several times before you can actually make changes to the text. Even then, you would have to re-enter the entire line of text just to change one word. The text editing features of AutoCAD have come a long way and it doesn't take the same painful effort it once did. The following program is a simple line editor which simplifies the task of editing a single line of text. It was designed for the older versions of AutoCAD before the Ddmodify and Ddedit commands were available. While its function may be a bit outdated, it will serve to demonstrate how to handle text in AutoLISP.

138

Copyright © 2001 George Omura,,World rights reserved