Autolisp 英文资料.doc_第1页
Autolisp 英文资料.doc_第2页
Autolisp 英文资料.doc_第3页
Autolisp 英文资料.doc_第4页
Autolisp 英文资料.doc_第5页
已阅读5页,还剩46页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

AutoLISP to Visual LISP: Design Solutions for AutoCAD Instructors GuideChapter OneDefinitionsSyntax - The way commands are arranged inside a computer program.Source Code - Is an ASCII text file containing a formal programming language. The source code file must be compiled, interpreted or assembled before a computer can use it. Flowchart - incorporates the use of graphic symbols to describe a sequence of operations or events. They are used to describe everything from the process involved in the treating of wastewater to the sequence of operations for a microprocessor.Pseudo-Code - A more natural way of preparing the source code for a computer program is with pseudo-code. In this method, standard English terms are used to describe what the program is doing. The descriptions are arranged in the logical order that they appear.GUI - A Graphical User Interface allows the user to interact with a computer by selecting icons and pictures that represent programs, commands, data files, and even hardware.Programming Language - The actual commands used to construct a computer program.Machine Language A program that is coded so that a computer can directly use the instruction contain within the program without any further translation.Hardware - is defined as the physical attributes of a computer, for example, the monitor, keyboard, central processing unit.Software - is defined as the programs or electronic instructions that are necessary to operate a computer.Binary - A number system that consist of two numbers one and zero. It is used extensively with computers because of its ease of implementation using digital electronics.Answers to Review Questions2. This process allows the programmer to gather the necessary information used to construct the application. It also allows the program to start laying out the actual program before the source code is created. Thus allowing the programmer to ensure the quality and accuracy a program. 3. State the problemList unknown variablesList what is givenCreate diagramsList all formulasList assumptionsPerform all necessary calculationsCheck answer4. Flowcharts use graphic symbols to represent a sequence or operation in a computer program, where as pseudo code uses standard English terms to describe what the program is doing.Flow ChartPsuedo-CodeStart ProgramPrompt user for InformationPerform CalculationsCheck AnswersDisplay AnswersEnd Program5. AutoLISP programs can be loaded into memory using one of two methods (the AutoLISP LOAD function or the AutoCAD APPLOAD command). The AutoLISP load function is a command line function that can be entered from the AutoCAD command prompt or placed inside of an AutoLISP application, where as the APPLOAD command is dialog based program that is executed from the AutoCAD command prompt.6. The compiler converts the source code from the language in which a program is created into a format that the computer can understand. 7. (Function1 Argument1)8. The Rich Text Format contains special commands used to describe important formatting information (fonts and margins).9. GUI and NonGUI. GUI systems include windows 95, 98 NT and 2000, just to name a few, where as nonGUI system include DOS, and OS400.10. The operating system is a set of program that is designed to controls the computers components. 11. The operating system is a set of programs that manages stored information, loads and unloads programs (to and from the computers memory), reports the results of operations requested by the user, and manages the sequence of actions taken between the computers hardware and software.12. A comment is the description placed in a program for the sole purpose of aiding the programmer in keeping track of what a program is doing.Chapter TwoAnswers to Review Questions1. 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 drawings life cycle. However an entity name is applicable only to a particular object in the current drawing session4. 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. *PRIN1Prints an expression to the command line or writes an expression to an open file*PRINCPrints an expression to the command line or writes an expression to an open file*PRINTPrints an expression to the command line or writes an expression to an open file*WRITE-LINEWrites a string to the screen or to an open fileNote: 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 () (setqNumberOne (getreal nEnter First Number : ) ) (Princ (- (+ (expt NumberOne 2) (* 2 NumberOne) ) 4 ) ) (princ)X4 + 4X3 + 7X2 + 1 (defun c:X4Function () (setqNumberOne (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 () (setqR1 (getreal nEnter R1 : )R2 (getreal nEnter R2 : ) ) (Princ (/ (+ R1 R2) (* R1 R2) (princ)(2 + 5) * ( 2 * ( 4 5) / 6)(* (* (/ (- 4 5) 2) (+ 2 5)DL / Lo(defun c:DeltaFunction() (setq NumberOne (getreal nEnter First Number : )NumberTwo (getreal nEnter Second Number : ) (Princ (/ (- NumberOne NumberTwo) NumberOne) (princ) )Chapter ThreeDefinitionsElement 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”.AtomNested 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 Questions2. 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 listCDR Returns a list starting with the second elementCADR Returns the second element of a listCADDR Returns the third element of a list(CAR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)Returns3.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)Returns5.98(CADDR (3.14 5.98 9.99 TEXT1 TEXT2 9.11 RED MONDAY)Returns9.996. By employing the AutoLISP STRCAT function7. 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) )Note: the underscores in the following Answers represent spaces16. Thi17. 5718. of_he19. anguage_t20._resistor tow is 500.00 volts21. (IF ( answer 10)(SETQ variable 11) )22. (IF (AND ( answer 5)(PROGN(SETQ VariableOne 7)(SETQ VariableTwo 20) )23. (IF (AND ( answer 2)(PROGN(SETQ VariableOne 15)(SETQ VariableTwo 50)(PROGN(SETQ VariableOne 1)(SETQ VariableTwo 2) )24. (IF (OR ( answer 2)(PROGN(SETQ VariableOne 15)(SETQ VariableTwo 50)(PROGN(SETQ VariableOne 1)(SETQ VariableTwo 2) )25. (this is an example list 1 3 4 5 T)26. this is an27. example list28. (example list 1 3 4 5 T)29. 130. (nth exampleList 4)31. 432. ; error: bad argument type: consp nil33. nil34. T35. example list36. (setq two (list A B C D)37. (append one two)38. (list one two)39. (append (list one two) three)40. (append (append (list one two three) three)one)41. (length (append (append (list one two three) three)one)42. (CADDR (append (append (list one two three) three)one)43. (list (append (append (list (list one two three) three (append one two) two three) three) two) three one)Chapter FourDefinitionsAssociation List - is a list in which the elements that are contained within are linked by an index.Dotted Pair A special type of sub-list contained within an association list in which the two elements are separated by a period.Extended Entity Data Provides the programmer with a means of storing and managing information in an objects association list using DXF codes. The attached information can be relevant or non-relevant to the particular entity.Graphic Entity is a visible object used to create a drawing (Lines, polylines, etc.).Loop is the continuous execution of a program or a portion of a program as long as a predefined test condition holds true.Non-Graphic Entities is any object that is not visible to the AutoCAD user (Layer, Linetype, Dimension Styles, Text Styles, Etc.).Answers to Review Questions2. In an association list the elements are linked to an index, where as elements in a list are not.3. In a dotted pair only one element is association with a unique index where as an association list can have multiple elements associated with an index.4. When an entity is created using ENTMAKEX an owner is not assigned.5. A loop can be created in an AutoLISP program by using either the WHILE or REPEATE functions.6. The NENTSEL function allows a program to directly access a nested entity contained within a complex object.7. CONS(CONS 8 “Example Layer Name”)8. SUBST(SUBST NewListItem OldListItem EntityList)9. ENTDEL10. True11. False, an AutoLISP association list can be modified by using the ENTMOD function.12. The AutoLISP WHILE function will continue executing a sequence of functions as long as the predefined test conditions holds true, where as the REPEAT function will execute a sequence of functions a predetermined number of times.13. False, In AutoLISP there is no limit to the number of loops that can be contained (nested) inside another or even one another.14. False, AutoLISP allows for loops to be placed within either an IF expression or a COND expression.15. False, The number of expressions that can be evaluated by a WHILE loop or REPEAT function is determined only by the placement of the closing parenthesis. 16. (3 . The value is 4)17. ; error: misplaced dot on input18. (4 . 0.65) (5 . 0.08)19. (-1 . ) (0 . LINE) (330 . ) (5 . 2B) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 8.17993 5.83581 0.0) (11 4.18605 3.58163 0.0) (210 0.0 0.0 1.0)20. 21. (-1 . ) (0 . LINE) (330 . ) (5 . 2F) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 1.98023 6.95455 0.0) (11 3.3338 4.83395 0.0) (210 0.0 0.0 1.0)22. 23. (-1 . ) (0 . LINE) (330 . ) (5 . 2B) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 8.17993 5.83581 0.0) (11 4.18605 3.58163 0.0) (210 0.0 0.0 1.0)24. 25. (this is an example list)26. (this is an example list)27. 28. 529. (-1 . ) (0 . LINE) (330 . ) (5 . 2B) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine) (10 9.84791 5.59698 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0)30. (10 9.84791 5.59698 0.0)31. ; error: too many arguments32. (-1 . ) (0 . LINE) (330 . ) (5 . 2C) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine(10 9.9 8.8 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0)33. ; error: bad argument type: (-1 . ) (0 . LINE) (330 . ) (5 . 2C) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 . AcDbLine(10 9.9 8.8 0.0) (11 5.12027 2.85854 0.0) (210 0.0 0.0 1.0)34. 35. (Setq num 10)(While ( num cnt) (setqnumberOne (getreal nEnter first number : )numberTwo (getreal Enter second number :) ); Malformed List (if (= numberOne numberTwo) (Princ nThe two number entered are the same : ) (setq answer (* numberOne numerTwo) );Malformed List (princ The products of the two numbers are (rtos answer)36. (while (= loop_cnt list_cnt) (setq resistor (nth loop_cnt resistor_list) (if (/= resistor nil) (setq equilivent_resistance (+ equilivent_resistance resistor) ) ) (setq loop_cnt (1- loop_cnt) 37. (DEFUN c:CalculateBtu()(SETQ Cnt 1TotalRFactor 0)(REPEAT 10(SETQ Prompt (STRCAT “nEnter the R value for material # “(Itoa Cnt) TotalRFactor ( +(GETREAL Prompt)TotalRFactor) Cnt (1+ Cnt) OutAirTemp (GETREAL “nEnter outside Air Temp : “) InAirTemp (GETREAL “nEnter inside Air Temp : “) WallLength (GETREAL “nEnter wall length : “) WallHeight (GETREAL “nEnter wall height : “) WallArea ( * WallLength WallHeight) Ufactor (/ 1.0 TotalRFactor) DeltaTemp (ABS (- OutAirTemp InAirTemp) BtuPerHour (* WallArea Ufactor DeltaTemp) )38. (DEFUN C:ChangeLine ()(SETQ Entity (ENTSEL “nSelect line to change”)(If (/= Entity Nil)(PROGN(SETQ Ent (ENTGET (CAR Entity)(IF (= (CDR (ASSOC 0 Ent

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论