Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
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 4: Interacting with the Drawing Editor

Introduction

Using Getreal and Getint

Prompting the User for Distances

How to Control User Input

How to Use Getdist

Using Initget

A Sample Program Using Getdist

Prompting for Dissimilar Variable Types

How to Get Angle Values

Using Multiple Keywords

Using Getangle and Getorient

How to Select Groups of Object

How to Get Text Input

Using Ssget

Using Getstring

A Sample Program Using Ssget

Using Getkword

Conclusion

How to Get Numeric Values

Introduction

In the first three chapters of the book, you learned the basics of AutoLISP. You now have a framework within which you can begin to build your programs. We can now discuss each built-in AutoLISP functions without loosing you in AutoLISP nomenclature. In this and subsequent chapters, You will be shown how each of the built-in functions work. Since the AutoLISP interpreter can be used interactively, you can enter the sample expressions shown in this chapter at the AutoCAD command prompt to see first hand how they work.

A key element in a user defined function is how it obtains information from the user. In this chapter, you will look at some built in functions that expedite your programs information gathering. You have already seen the use of two of these functions, Getpoint and Getcorner, in chapter 2 and 3.

70

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

Prompting the user for Distances

You will often find the need to prompt the user to obtain a distance value. At times, it is easier for the user to select distances directly from the graphic screen by using the cursor. AutoLISP provides the Getdist function for this purpose.

How to use Getdist

The syntax for Getdist is:

(getdist [optional point value] [optional prompt string])

You can optionally supply one or two arguments to Getdist. These arguments can be either string values which will be used as prompts to user when the program runs, or point values indicating a position from which to measure the distance. Getdist will accept both keyboard input as well as cursor input and it always returns values in real numbers regardless of what unit style is current. This means that if you have your drawing set up using an architectural unit style, Getdist will return a value in decimal units. The following exercises will demonstrate these uses.

There are three ways to use Getdist. First, you can use it to input a distance by picking two points using the cursor. For example:

1.Open a file called Chapt4=. Set the snap mode and dynamic coordinate readout on.

2.Enter the following:

(setq dist1 (getdist "Pick point or enter distance: "))

The prompt line will display:

Pick first point or enter distance:

This prompt is the same as the string value used as the argument to Getdist. At this prompt, you can enter a numeric value in the current unit style or in decimal units or you can pick a beginning point using the cursor.

3. Pick a point at coordinate 3,3 with your cursor. You will get the prompt:

Second point:

and a rubber banding line will appear from the first point selected.

4.Pick a second point at coordinate 8,3 with you cursor, the distance between the two points selected is assigned to the variable dist1.

5.Enter the following:

!dist1

71

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

The distance value stored by dist1 is displayed.

5.0

Using the same expression as above, you can also enter a distance value at the keyboard. 1. Enter the following:

(setq dist1 (getdist "Pick point or enter distance: "))

The prompt line will display:

Pick first point or enter distance:

2.In the previous exercise, you picked a point at this prompt and Getdist responded by asking for a second point. Instead of picking a point, enter the value of 6.5. Once you have done this, 6.5 is assigned to the variable dist1.

3.Enter the following:

!dist1

The distance value stored by dist1 is displayed.

6.5

A third way to use Getpoint is to supply a point variable as an argument.

1. Enter the following at the command prompt:

(setq pt1 (getpoint "Enter a point: "))

When the Enter a point prompt appears, pick a point at the coordinate 3,3. The coordinate 3,3 is assigned to the variable pt1.

2. Enter the following expression:

(setq dist1 (getdist pt1 "Enter a second point: "))

Notice that the variable pt1 is used as an argument to getdist. A rubber-banding line appears from pt1 and the prompt displays the string prompt argument you entered with the expression.

3.Pick a point at the coordinate 9,6. The distance from pt1 to the point 9,6 is assigned to the variable dist1.

4.Enter the following to get the distance stored by dist1:

!dist1

6.7082

As you can see, getdist is quite flexible in the way it will accept input. This flexibility makes it ideal when you need

72

Copyright © 2001 George Omura,,World rights reserved

The ABC’s of AutoLISP by George Omura

to get sizes of objects from the user. The user has the flexibility to either enter a size value at the keyboard or visually enter a size by picking points from the drawing area. The rubber-banding line provided by getdist allows the user to visually select a size. Several AutoCAD commands act in a similar manner. For example, the Text command allows you to select a text size either by entering a height or by visually selecting a height using your cursor. Figure 4.1 summarizes the three ways you can use Getdist.

Figure 4.1: Three methods that Getdist accepts for input

73

Copyright © 2001 George Omura,,World rights reserved