Cadence feb Gdk user library



Download 73.07 Kb.
Date05.05.2018
Size73.07 Kb.
#48003
cadence.feb GDK

user library

IMAGINARY OSNAP
by Chris Fawcett

The program Imaginary Osnap (Listing 1) lets you "snap" to intersections that do not actually appear on the drawing, eliminating the hassle of extending objects to meet each other, picking the intersection, and then trimming back the unneeded entities. It "snaps" to the intersection of any combination of lines, arcs, and circles and works transparently in all AutoCAD commands that require point selection.

To use this program, load it and then at any prompt to pick a point, type (imag). The program prompts for two objects. Pick any two objects (lines, arcs, or circles), and their point of intersection is entered for the AutoCAD command. In my office we have found it valuable to replace one of the least-used Osnap commands on our tablet (in our case, "None") with this imaginary intersection. This worked so well that a new operator thought the command was an original AutoCAD command until he tried to look it up

in the manual.

One of the most common uses we have found for this program is in dimensioning, especially dealing with fillets. When you fillet a line, you lose the intersection of the two lines, which is the one intersection we most often want to dimension. Sometimes this problem can be solved by the x and y filters with AutoCAD, but only when working with vertical and horizontal lines. We find it much easier to use (imag) instead. ?
Chris Fawcett can be reached at Fawcett Design, 136 N. Water St., Ste. 203, Kent, OH 44240.

Working with Loops


by Leif Eriksen

When we write an AutoLISP program, we expect it to be executed in sequence, from top to bottom. This is a basic assumption in most programming languages. However, since we want our program to react properly to whatever data it encounters, we often have to create detours in the code, such as user-defined functions and conditionals like if and cond.

Programming often arises from the need to solve a problem involving much data. Often, each datum in our data set is similar to the others. Since we do not always know in advance how many datums we must deal with and since a separate line or two to deal with each datum would make the program huge in any case, iteration, or looping, is used.

Looping controls the execution flow of a program. While in a loop, the computer will repeat a number of functions, in sequence, until a condition indicates it should exit the loop. If the condition is not satisfied, the loop continues forever (or until you interrupt with a control-C or reboot); this is called an "endless loop."

AutoLISP uses three functions to perform a loop: while, repeat, and foreach. Each is used in different situations.
WHILE

The while function is probably the most commonly used looping function. While has two or more arguments. The first argument is the looping condition, which controls whether the loop continues or terminates. If the loop terminates, AutoLISP resumes from the first function following the while. The additional arguments are the functions inside the loop. The while function (as well as repeat and foreach) return the value of the last function in the loop. We are seldom concerned with the value returned by while;

instead, we use it for its loop effect.

While checks the value of its condition when it first starts. If the value of the argument is nil, then the other arguments are never executed; while loops only when its condition is anything but nil. This test is made at the top of the loop. After all the functions in the loop have been executed, control jumps back up to the top of the loop. The condition is then checked again. If not nil, the loop continues. If nil, then the loop quits.

The CNTTYPE program (Listing 1) in the December and January issues is a good example of the while function. It counts the number of entities and their types in the current drawing. Notice in CNTTYPE that the while loop begins with the fourth line. It is controlled by the variable en (for entity name). If the drawing is empty (has no entities) the entnext function on the third line will return nil. When while is first started, if the condition is nil, then the functions within the loop are ignored. That woul

d happen if no entities were in the drawing.

Suppose we run this program on a drawing that had several entities. The variable en would have a value (like ) that is not nil. So while would execute all the functions within it. Functions within a loop are normally indented a few spaces to help document the fact that these functions are within the while. Beware, however, that the indenting is ignored by AutoLISP. What is within the while loop is solely controlled by the closed parenthesis for the while.

The last function within the while, line 12, gets the next entity name (en), with the entnext function. The while loop tests this value, as before, and if it is not nil, the loop goes through again. If the value is nil, AutoLISP continues with line 16.

The result of a conditional function can also control a while loop. In the following program fragment, the first 10 entity names of a selection set are passed to a function prtfun. However, a check is also made, and if the selection set has less than 10 entities, the while loop exits.
(setq idx ) en)

(prtfun idx en)

(setq idx (1+ idx))

(setq en (ssname ss idx))

)
The first two lines initialize the index variable, idx, and the entity name variable, en. While idx is less than 10 and en is not nil, the loop will continue. The last two statements reinitialize idx and en. If idx reaches 10, the function (< idx 10) will return nil. If any argument of the and function is nil, it will return nil, so the loop quits. If idx is less than 10, but en is nil (because ss has fewer than 10 elements), the and function again will return nil and the loop will exit.
REPEAT

The repeat function is another way to create a loop in AutoLISP. It has two or more arguments; the first is the number of times you want repeat to loop. This number must be an integer. If you have a real or floating-point number, use the fix function to convert it to an integer before it is used by repeat. The second and additional arguments are the AutoLISP expressions you want in the loop.

The repeat function is not as flexible as the while function since you must specify the number of times you want repeat to loop. However, if you need to process a loop a fixed number of times, repeat is more efficient than while. The speed difference is dramatic. To make the while loop perform like a repeat, we must introduce a variable and increment it each time through the loop. The AutoLISP functions in Listing 2 show a program I used to test the performance of the repeat and while functions. I ran both

on a 16MHz 386SX machine using AutoCAD Release 11. The repeat function ran in 3.62 seconds; the while function took 14.99 seconds.

I next took out the statement (setq a 0) in both loops (Listing 3). The results were surprising. The repeat took 0.11 seconds, and the while took 11.48 seconds. At first I thought AutoLISP was not performing the repeat loop since it contained no expressions. However, the time difference between the first and second test of the repeat (3.62 _ 0.11 = 3.51) was exactly the same as the difference in time between the first and second test of the while (14.99 _ 11.48 = 3.51). From this I conclude that AutoLISP do

es not optimize its loops by not performing them if they don't contain functions. The raw time difference between the repeat and while, set up to work like repeat, is about 100 times (0.11 versus 11.48).

What is a practical application of the repeat function? Listing 4 shows a short program that blanks the text screen by sending out 24 blank lines.
foreach

The foreach function helps process lists. As with repeat, the action of foreach could be simulated with a while function. However, foreach saves a few steps by automatically extracting the next element from a list and assigning it to the specified variable name.

Foreach has three or more arguments. The first argument is the variable name used to assign the current list element. The second argument is the list to be processed. The remaining arguments are the expressions that are part of the foreach loop.

Listing 1 has a good example of the foreach function. It builds an association list of entity types and counts for the current drawing. Starting on line 17, the foreach function is used to assign each element of elist to a variable called etlist. From this the entity type and count are displayed. Last month I used the while function, instead of foreach (i.e., I was using while to simulate the action of foreach). Using while the loop looks like the following:


(while elist

(setq etlist (car elist))

(terpri)

(princ (pad (car etlist) 15))

(princ (cadr etlist))

(setq elist (cdr elist))

)
This is less efficient and more confusing than using foreach.

Of the functions that perform loops, the while function is the most common and flexible. However, do not overlook repeat and foreach. Both have "niche" uses to clarify and increase the speed of programs. Next month we will continue with entity access to tables and see how you can use AutoLISP to access blocks and other table items. ?


Leif Eriksen is president of Discovery Systems, an AutoCAD training and consulting firm in Irvine, Calif.
Questions

1. What happens if you use a floating-point number as the first argument to the repeat function? What can you do to correct the problem?

2. When is it desirable to use the foreach function?

3. The while will keep looping until what happens?

4. How many times will foreach loop?
Answers

1. You will get a bad argument type error. You can correct the problem by converting the floating-point number to an integer with the fix function.

2. When you need to process every element in a list.

3. Until its condition becomes nil.

4. It will loop once for each element within its list. If your foreach function is like (foreach name list . . .), it will loop (length list) times.

AutoLISP Graphic Calculators


by Bill Kramer

AutoLISP provides an easy-to-use calculator inside AutoCAD, if one takes the time to learn the basics. Most AutoCAD operators are immediately turned off by the parentheses and prefix notation used in AutoLISP and hence do not use this valuable asset. On the other hand, most operators do not seem to mind using the explanation point prior to a variable name supplied from an AutoLISP application. For example, suppose we have a program that calculates the location of a point and saves it in the symbol p1. If p1

is a global (free) variable, the operator can type "!p1" to retrieve the value of p1 in response to an AutoCAD command prompt such as "Next point." Similarly, a set of problem-solving routines can be created for operators to calculate input to AutoCAD commands.

This month, we will create an AutoLISP calculation tool. We will also demonstrate how slides can be used to provide graphic help and how output from an AutoLISP program can interact with a slide display. The tool we will develop solves the basic trigonometric equations associated with right triangles.

Figure 1 shows a right triangle with the sides and angles labeled. The function we are creating will accept input from the operator describing the inside angles and/or the leg sizes. After two items of input have been supplied, the function will calculate the remaining sides and angles. The results will then be shown to the operator with a scaled picture of the triangle described. Although the equations would be different, the operational sequence of this function can be duplicated for other engineering/des

ign equation-solving functions.


Function Components

The first problem involves the solutions of a right triangle. There are five equations that can be used to solve all the values of a triangle (Figure 2). In writing a function to solve any of these equations, given any of the variables, we have to separate the problem into smaller ones. In looking at the equations in Figure 2, the hypotenuse c is used frequently. Thus, it is the logical choice to solve first.

Listing 1 contains the function tri:c, which solves the variable c given any of the possible permutations of input. If the values of sides a and b are supplied, the value of c is the square root of the sum of a squared and b squared. If side a and angle aa are known, c is the result of dividing a by the sine of aa. The other input variable permutations for solving c are programmed the same way.

Once c is known, only the equations requiring c are required to determine the remaining values. Listing 2 contains two functions that solve for the a, b, aa, and bb variable values using the variable c: tri:ab, which calculates the sides values, and tri:aabb, which calculates the angle values. Tri:ab has four parameters: sym, ab, aa, and bb. Sym is the symbol name (either 'a or 'b) of the variable to be calculated. The function tri:ab sets a value for this symbol as a side effect. Ab contains the value of t

he alternate side variable (a or b) or nil if it is unknown. The variables aa and bb represent the opposite and adjacent angles, respectively. On the condition that both ab and c have values, the other side's size is found by computing the square root of the difference of c squared and ab squared. Otherwise, if the opposite angle (aa) and c are both known, the value of the side in question is found by multiplying c by the sine of the opposite angle. Finally, if the adjacent angle (bb) and c are known, multi

plying c by the cosine of the adjacent angle will give the value desired.

Note that the set subroutine is used instead of setq. In the tri:ab function parameters, we passed the symbol of the variable to be changed. In essence, this is AutoLISP's method of "call by reference." Normally, AutoLISP is a "call by value" language in which the values assigned to a symbol are sent to a function instead of where the value is stored. By using a quoted symbol name in the call to the tri:ab function, we are passing the symbol name only. Using the symbol name, we can access where the value is

stored in the function that called the tri:ab function. The set subroutine performs the same function as setq, but it evaluates the symbol sym to get the symbol name of the variable to set.

The function tri:aabb uses sym for the angle calculations. The four parameters to tri:aabb are sym, ab, a, and b. Sym is the symbolic name (either 'aa or 'bb) of the angle to be calculated; ab is the "known" angle value; a is the opposite side value; and b is the adjacent side value. The first test is to see if the angle variable ab has a value. If it does, the value at the sym address is set to the value of subtracting ab from 90 degrees (pi/2). If the opposite side (a) and the hypotenuse (c) are known, th

e angle ab can be calculated as the arc sine of the a divided by the c. If the adjacent side (b) and the hypotenuse (c) are known, the angle ab is the arc cosine of b divided by c. Listing 4 describes the asin and acos functions used in this calculation.

A function to calculate the triangle values can now be created. Listing 3 contains the function tri:solve, which calls the tri:c, tri:ab, and tri:aabb functions to determine the values of the triangle's sides and angles, given any two values for input. Tri:c is called first if the value of c is unknown. The functions tri:ab and tri:aabb were built based on the assumption that c would be known in virtually all cases. If aa is unknown, the function tri:aabb is invoked with the parameters 'aa (unknown angle sy

mbol), bb (other angle), a (opposite side), and b (adjacent side). If bb is not known, tri:aabb is called with the appropriate variables as parameters. The same is performed when either side a and b are unknown using the tri:ab routine. After running all these functions, each variable (a, b, c, aa, bb) will have been assigned a value. The only case where variables would not be set is if aa and bb are the inputs provided with no side values. As long as the function is used properly, this should never happen.


With the calculation function ready, now the input and output routines need to be written. Listing 5 contains three functions: tri:inp (for input), tri:out (for output), and c:rtrl (the main user command function, which simply calls tri:inp, tri:solve, and tri:out). This program was created with the concept that the routines would be modified to perform additional calculations. The modified functions would be clones created from the provided routines.

Tri:inp begins by initializing all the variables a, b, c, aa, and bb to nil, and the variable n to 0 (n is a counter that will be used to determine how many input variables have been supplied). A help slide is then displayed on the screen. The name of the help slide is the only input parameter to tri:inp. Two input variables are needed to solve the triangle values.

A while loop is started that will continue as long as the value of n is less than 2. Inside the while loop a getstring is used to obtain the variable to be set by the operator. The operator is expected to input the exact, case-sensitive variable name. For example, "A" and "Aa" would be invalid, but "a" and "aa" would be accepted. After the getstring, the value of the variable s is tested to see if it is a member of the list of valid responses. If s is a member of the list, a progn is started.

Inside the progn, the variable tmp is established as either being the value of the variable selected or the string "nothing." The test (eval (read s)) converts s to a symbol and then evaluates the symbol. If the symbol points to a non-nil value, the test is considered true. In that case, there is data in the symbol and it is obtained again through the (eval (read s)) expression. If the value of s is either "aa" or "bb," the value is converted from radians to degrees by the function dtr (Listing 4). Otherwis

e, the result of the (eval (read s)) expression is passed to the rtos subroutine for conversion to a string.

A getreal is then used to obtain the new value from the operator. The value in tmp is concatenated to the prompt string to show the default. Tmp is either the string "nothing" or the current value of the variable selected. The result of getreal is saved in tmp. If tmp has a binding (i.e., if the operator entered data during the getreal), a progn is started. A test is made to see if a value exists for the current symbol in question. The expression (eval (read s)) returns the current value of the symbol in s

tring s. If the symbol is bound to nil, the null subroutine is true and the variable n is incremented.

A set subroutine is used to save the result of the operator input into the symbol name in string s. The code fragment (read s) returns only the symbol (eval is then needed to get the value.) The value saved is modified if s is either "aa" or "bb" by converting the operator input of degrees into radians.

Tri:inp sets the global variables a, b, c, aa, and bb to their initial values, and its return value is not important. The next function executed is tri:solve, which calculates the remaining variables. After tri:solve, tri:out is invoked to write the results to the screen.

Tri:out performs two basic functions. First, it outputs the results of the calculations for the triangle variables. Second, it draws a scaled version of the triangle as described that corresponds to the graphic model presented. Tri:out assumes the that slide output to the screen in tri:inp is still present and that the slide in use conforms to some simple rules for overlay location of the new graphics. The display can be at any zoom factor when a slide is placed over the drawing area. The slide is always di

splayed at the same size as it was created, but the coordinate system of the display does not change. To define locations on the slide, we need to use the AutoCAD system variables VIEWSIZE and VIEWCTR.

Tri:out begins by setting the variable tmp to the value of VIEWSIZE. Tp1 is then set to the value of VIEWCTR. The text insertion point for the answers is located at the same y value of the view center point but one-quarter display height away in the x direction. Tp1 is reset to the list created by taking the x coordinate of tp1 (the car), adding one-fourth of the value of tmp, and then appending the y coordinate (cadr) to make a list. The text size is then determined as being the display height divided by 3

0.

Next, the output string values for the variables are determined. If they do not have a value, the string "Unknown" is saved for output to the display. Otherwise, the rtos of the values is saved in the output variables. The Text command is used to output the strings to the screen. The first line of text is output at position tp1, with a size of tsz. The string in oa is sent to the graphics display and is displayed over the top of the slide. The entity name of the text output is saved using entlast in the var



iable el. (Later, we will want to remove these text items from the screen. The remaining text strings are output using the default line controls of the AutoCAD text command. Note that the Text command string must be stated each time; an enter key "" will not repeat the last AutoLISP command output.

If all the variables (a, b, c, aa, and bb) are known, a scaled triangle of the shape described is drawn in the lower left part of the screen. The starting point of the triangle is at an angle 1.2 * pi and at a distance of the view size divided by 1.5 from the view center point. When making up your own graphical feedback, locate the base point of the parametric shape relative to the center point for easy programming. Use the Line command to define center point to starting point information.

The triangle drawn by tri:out is scaled by a factor. The variable fkt is set to the length of the hypotenuse divided by the screen height and multiplied by three. The length values of the triangle are then divided by this factor to obtain the display length. Grdraw is used to create the triangle graphics on the display. The lines are drawn using color code 2 (Yellow) while the temporary points tp2 and tp3 are saved. The legs are connected by drawing from tp2 to tp3. A getstring then waits on the operator t

o press to continue.

After the getstring wait, the text entities just added are erased. A while loop is started that continues until the symbol el has no value. Inside the while loop, the entity el is deleted using entdel. El is then updated to the name of the next entity via entnext. Entnext returns nil when the last entity is used as a parameter. The nil result terminates the while loop and the function then performs a screen redraw and returns to c:rtrl, which ends with a princ for a quiet return to AutoCAD. The screen is r

eturned to normal and operation can now continue inside the drawing editor. A side effect of c:rtrl is that the variables a, b, c, aa, and bb are considered global. They can be used in other calculations and programs as desired by the systems integrator.

The right triangle calculator sets the direction for more utilities of this nature. Calculation utilities that are more advanced could be created that use multiple viewports with slides and object selection for input. The structure and concepts of these calculation systems would basically be the same as presented in the rtrl command function.

We are always looking for ideas on what to write about in Advanced AutoLISP Concepts. If you have a suggestion please send it to Bill Kramer, c/o Ariel Communications. Until next month, keep on programming! ?


Bill Kramer is the president of Auto-Code Mechanical, a software development and publishing firm in Dublin, Ohio that specializes in mechanical and manufacturing applications.
Figure 1. Right triangle. The operator can input values for angles and leg sizes, and the function will calculate the remaining values. The results are shown to the operator with a scaled picture of the triangle.
(on 31/2" disk)

Figure 2. The five equations for solving the values of a triangle.


Listing starts on next page

arcs
by Joe Pucilowski

The Arc command can be confusing, especially to beginners, because of its many options and the sometimes non-intuitive steps involved. Probably the most common way to draw an arc is with the Fillet command; since Fillet takes care of tangencies automatically it's the clear choice in most situations. But when tangencies aren't required or there are no objects to fillet between, the Arc command is preferable.

The following examples illustrate all the options of the Arc command in the order they appear in the Release 11 screen menu. (If you're drawing these examples as you read this, the numbered dots in the figures indicate the order of picking.)

The simplest way to draw an arc is the three-point method (Figure 1). You pick points 1 and 2, drag the arc into place, and pick point 3.
Command: Arc

Center/: pt 1

Center/End/: pt 2

End point: pt 3


Note that you can't make points 1 and 3 the same point (i.e., you can't draw a circle with the Arc command). The included angle of any arc, three-point or otherwise, must be less than 360 degrees.
Start, Center, End

This option draws an arc counterclockwise from the start point to the endpoint, about a given center (Figure 2).


Command: Arc

Center/: pt 1

Center/End/: c

Center: pt 2

Angle/Length of Chord/: pt 3
Point 3 doesn't actually have to be on the arc. The endpoint of the arc will not pass beyond a temporary line drawn from point 2 to point 3. This line establishes the ending angle of the arc.
Start, Center, Included Angle

This option creates an arc clockwise or counterclockwise from the start point, based on the sign of the included angle. That is, a positive angle forces the arc counterclockwise, and a negative angle forces it clockwise (Figures 3 and 4). If you've forgotten what an included angle is, this example probably didn't make much sense. Two imaginary lines, one from the center to the arc's first endpoint, and one from the center to other endpoint, form the included angle.


Command: Arc

Center/: pt 1

Center/End/: c

Center: pt 2

Angle/Length of Chord/: a

Included angle: 19


Start, Center, Length of Chord

Recall that a chord is a line connecting the endpoints of an arc. With this option we'll again pick a start and center point and then supply a chord length (Figure 5).


Command: Arc

Center/: pt 1

Center/End/: c

Center: pt 2

Angle/Length of Chord/: L

Length of chord: 1.2


Whenever you supply a positive chord value, the arc will be less than 180 degrees. If we had used -1.2 for the chord length, AutoCAD would have drawn the largest arc possible for the given start and center points. Also, any chord longer than twice the arc radius is an invalid chord.
Start, End, Included Angle

Similar to start, center, included angle, this option accepts a signed angle to force the arc clockwise or counterclockwise. Or as in these examples, the arc can also be dragged into place (Figure 6).


Command: Arc

Center/: pt 1

Center/End/: e

End point: pt 2

Angle/Direction/Radius/

: a

Included angle: 18.5


Start, End, Direction

With this option you pick a starting and ending point, then drag the arc into place, and pick a third point. As you drag the arc, you'll notice it always remains tangent to the temporary line strung from point 1 to point 3. This line represents the tangent direction (Figure 9).


Command: Arc

Center/: pt 1

Center/End/: e

End point: pt 2

Angle/Direction/Radius/

: d

Direction from start point: pt 3


Center, Start, End

Similar to start, center, end, this option requires three points, with the third point not required to be on the arc (Figure 10).


Command: Arc

Center/: c

Center point: pt 1

Start point: pt 2

Angle/Length of chord/: pt 3
Center, Start, Included Angle

Again we have to deal with an included angle. This time, however, we'll drag the arc into place.

The angle between an imaginary horizontal line passing through point 1 and the temporary line from point 1 to point 3 forms the included angle. The coordinates at the top of the screen give the approximate angle measurement as you drag point 3 into place (Figure 11).
Command: Arc

Center/: c

Center point: pt 1

Start point: pt 2

Angle/Direction/Radius/

: a

Included angle: pt 3


Center, Start, Length of Chord

As with start, center, length of chord, we can force a major or minor arc by changing the sign of the length. This time, however, we'll drag the chord; the distance between points 2 and 3 indicates the chord length (Figure 12).


Command: Arc

Center/: c

Center: pt 1

Start point: pt 2

Angle/Length of chord/: L

Length of chord: pt 3


Notice that the direction you drag the temporary line doesn't matter, but its length does. Also, remember that the chord length can't be more than twice the arc's radius.
Arc Continuation

Arc continuation allows you to draw a series of connected arcs that are always tangent to each other. You can draw your first arc with any option you like and then continue to draw connected arcs for as long as you like (Figure 13).


Command: Arc

Center/: pt 1

Center/End/: pt 2

End point: pt 3

Command: Enter

ARC Center/: Enter

End point: pt 4

Command: Enter

ARC Center/: Enter

End point: pt 5


In this case we started with a three-point arc and added two arcs after it. The continuation arcs behave similar to the tangent direction option we already used. The starting direction of the new arc is taken from the endpoint and ending direction of the previous arc.
Line and Arc Continuation

Line and arc continuation can be used together to keep everything tangent. In this example we'll draw a line, continue with an arc, and then continue with another line (Figure 14).


Command: Line

From point: pt 1

to point: pt 2

to point:

Command: Arc Center/:

End point: pt 3

Command: Line

From point:

Length of line: pt 4

to point:


Retrieving Arc Information

The List command can be used to retrieve information about any entity onscreen. Listing an arc returns its radius, center point, starting angle, and ending angle. This is good information, but we'd also like to know the included angle, the chord length, the chord bearing, and most important, the arc length.

Fortunately, an AutoLISP program can do this (Listing 1). To test ARCLIST, draw a three-point arc with coordinates 1,1, 2,2, and 3,2; you should get the same results we have here:
Command: ARCLIST

Pick an arc: pick the arc

Arc length = 2.4836

Included angle = 96.5651


The current settings for linear and angular units (set with the Units command) controls the precision and format of the values returned by ARCLIST.
Joe Pucilowski is president of Joseph & Associates, an AutoCAD training and consulting firm in Tampa, Fla.

Tips And Tricks


by Tandy Willeby

CADENCE Staff

In addition to this month's collection of LISP routines, I would like to address a problem that seems to be haunting AutoLISP users with AutoCAD versions prior to Release 11. This problem occurs when using AutoLISP routines written for the newer AutoCAD version. Although there are very few differences in the basic command structure between Release 11 and earlier versions, a change in the Text and Dtext commands is making life difficult for pre-11 AutoCAD users. With Release 11, an additional option is avail

able to display the justification choices for the text. The program does not require the justification option to be selected before the type of justification can be entered; however, some programmers use the "j" option in their code. This does a good job of killing the program when run under older versions of AutoCAD. For example, a LISP code segment for entering right-justified text in a drawing in Release 10 would read:


(command ".Text" "r" ip ht ang "text string")
The same code in Release 11 would read as either one of the next two:
(command ".Text" "j" "r" ip ht ang "text string")

(command ".Text" "r" ip ht ang "text string")


In addition to the use of the justification option, the number of justification types has been increased (Table 1). To allow the newer routines to run, you must replace the new justification type with its closest counterpart in your AutoCAD version. If you get an error in an early version of AutoCAD when running a Rel. 11 LISP routine that uses text, this is the first place you need to look. And when creating code that deals with text, either use the old standard justifications or the ver function to determ

ine what kind of justification to use, as in:


(if(= (ver) "AutoLISP Release 11. "test string")
This will make the code a little more portable between versions and much friendlier. ?
A - Aligned

F - Fit


C - Center

M - Middle

R - Right

TL - Top Left

TC - Top Center

TR - Top Right

ML - Middle Left

MC - Middle Center

MR - Middle Right

BL - Bottom Left

BC - Bottom Center

BR - Bottom Right


Table 1. Release 11 text justification types.


Download 73.07 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page