Autolisp to Visual lisp: Design Solutions for Autocad instructor’s Guide Chapter One



Download 210.39 Kb.
Page2/8
Date05.05.2018
Size210.39 Kb.
#47999
1   2   3   4   5   6   7   8

Answers to Review Questions

1. In AutoLISP an integer is any whole number that ranges from –2,147,483,648 to +2,147,483,647, where as a real number is any any number including zero that is positive or negative, rational (a number that can be expressed as an integer or a ratio of two integers, ½, 2, –5) or irrational (square root of 2).


2. The GETREAL function returns a true real number where as the GETSTRING will return the value converted to a string.
3. When an object is created in AutoCAD, it is given a handle that is used when referencing information concerning that object. The handle that is assigned to an entity remains constant throughout the drawing's life cycle. However an entity name is applicable only to a particular object in the current drawing session
4. Local Variables are only available to the function in which they are defined, where as global variable are available to the entire program.
5.

(DEFUN program (/ pt1) ;Pt1 is declared as a local ;variable.

(function argument) ;Expression.

(function argument) ;Expression.

)
6. File descriptors, just like entity names, are alphanumeric in nature and are only retained in the current drawing session or as long as the external file is open for input/output. Any time that an attempt is made to write, append, or read to a file, the file descriptor must be identified in that expression.
7. The AutoLISP OPEN function.
8.

*PRIN1

Prints an expression to the command line or writes an expression to an open file

*PRINC

Prints an expression to the command line or writes an expression to an open file

*PRINT

Prints an expression to the command line or writes an expression to an open file

*WRITE-LINE

Writes a string to the screen or to an open file

Note: All definitions starting with a * were taken from the AutoLISP Programmers Reference.


9.
Given the following equations write an AutoLISP expression for each.

X2 + 2X – 4

(defun c:X2Function ()

(setq NumberOne (getreal "\nEnter First Number : ")

)

(Princ (- (+ (expt NumberOne 2)



(* 2 NumberOne)

)

4



)

)

(princ)



)
X4 + 4X3 + 7X2 + 1

(defun c:X4Function ()

(setq NumberOne (getreal "\nEnter First Number : ")

)

(Princ (+ (expt NumberOne 4)



(expt (* 4 NumberOne) 3)

(expt (* 7 NumberOne) 2)

1

)

)



(princ)

)
R1 + R2 / (R1)(R2)

(defun c:RFunction ()

(setq R1 (getreal "\nEnter R1 : ")

R2 (getreal "\nEnter R2 : ")

)

(Princ (/ (+ R1 R2) (* R1 R2)))



(princ)

)
(2 + 5) * ( 2 * ( 4 – 5) / 6)

(* (* (/ (- 4 5)) 2) (+ 2 5))
L / Lo

(defun c:DeltaFunction()

(setq NumberOne (getreal "\nEnter First Number : ")

NumberTwo (getreal "\nEnter Second Number : ")

)

(Princ (/ (- NumberOne NumberTwo) NumberOne))



(princ)

)

Chapter Three



Definitions

Element – is an individual entity contained within a list. For example the list (Red Yellow Green) contains the elements: Red, Yellow and Green.


Truncate – To shorten a text string by removing a portion of that string. For example the text string “This is an example” is a truncated sub string of the text string “This is an example of a truncated string”.
Atom
Nested Function – A nested function is a function that is contained within another function. The nesting of functions is most often attributed with If statements and loops.

Answers to Review Questions

2. A list is capable of containing a varying amount of information. The use of list also reduces the amount of variables required in a program. They provide an efficient as well as a practical way of storing information over the traditional methods of using variables.


3. LIST (LIST 3.14 2.68 9.99 Text)
4.) Two or more list maybe combined into a single list by using either the AutoLISP function LIST or APPEND. The LIST function when supplied with multiple list as arguments, returns a single list in which its elements are the individual lists that were originally supplied to the LIST function. For example
(LIST

(3.14 5.98 9.99)

(TEST1 TEST2)

(9.11 RED MONDAY)

)
Returns
((3.14 5.98 9.99)(TEXT1 TEXT2)(9.11 RED MONDAY))
The APPEND function on the other hand merges the elements of multiple list into a single list in which its elements are the elements of the supplied lists. For example
(APPEND

(3.14 5.98 9.99)

(TEST1 TEST2)

(9.11 RED MONDAY)

)
Returns
(3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)


  1. CAR – Returns the first element of a list

CDR – Returns a list starting with the second element

CADR – Returns the second element of a list

CADDR – Returns the third element of a list
(CAR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)

)

Returns



3.14
(CDR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)

)

Returns



(5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)
(CADR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)

)

Returns



5.98

(CADDR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)

)

Returns


9.99
6. By employing the AutoLISP STRCAT function
7. False, before numeric data can be combined with a string, it must first be converted from its native data format into a string data type. For real numbers this is accomplished by using the RTOS function. For integers this is accomplished by using the ITOA function.
8.) False, in AutoLISP a string can be truncated using the SUBSTR function.
9. In AutoLISP decisions can be made by using either the IF function or the COND function. The COND function differs from the IF function in the respect that the program is allowed to use multiple test expressions, with each having its own THEN ELSE arguments.
10. The AutoLISP PROGN function allows a program to evaluate multiple expressions sequentially and return the result of the last expression evaluated.
11. (SETQ ReturnString (STRCAT “This is an example “ “of an AutoLISP “ “String”)

)
12. (SETQ ReturnString (STRCAT “The Amount of heat loss is “

(RTOS 456.87)

“ btu/’hr”

)

)
13. (SETQ ReturnString (STRCAT “The square root of “



(ITOA 2)

“ is “


(RTOS 1.4142)

)

)


14. (SETQ ReturnString (STRCAT “The program has completed ”

(ITOA 57)

“ cycles”

)

)


15. (DEFUN c:ChapterThree15Answer ()

(SETQ NumberOne (GETREAL “\nEnter NumberOne : “)

NumberTwo (GETREAL “\nEnter NumberTow : “)

)

(PRINC (STRCAT



“\nThe product of the two numbers “

(RTOS NumberOne)

“ and “

(RTOS NumberTwo)



“ is “

(RTOS (* NumberOne NumberTwo))

)

)

(PRINC)



)



Download 210.39 Kb.

Share with your friends:
1   2   3   4   5   6   7   8




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

    Main page