Chapter Three
AutoLISP to Visual LISP: Design Solutions for AutoCAD
Instructor’s Guide
Chapter One
Definitions
Syntax - 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 Questions
2. 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 problem |
|List unknown variables |
|List what is given |
|Create diagrams |
|List all formulas |
|List assumptions |
|Perform all necessary calculations |
|Check answer |
4. 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 Chart
[pic]
Psuedo-Code
Start Program
Prompt user for Information
Perform Calculations
Check Answers
Display Answers
End Program
5. 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 computer’s memory), reports the results of operations requested by the user, and manages the sequence of actions taken between the computer’s 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 Two
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)
)
Note: the underscores in the following Answers represent spaces
16. Thi
17. 57
18. of_he
19. anguage_t
20._resistor tow is 500.00 volts
21. (IF (< answer 10)
(SETQ variable 11)
)
22. (IF (AND (< answer 6)(> answer 5))
(PROGN
(SETQ VariableOne 7)
(SETQ VariableTwo 20)
)
)
23. (IF (AND (< answer 6)(> answer 2))
(PROGN
(SETQ VariableOne 15)
(SETQ VariableTwo 50)
)
(PROGN
(SETQ VariableOne 1)
(SETQ VariableTwo 2)
)
)
24. (IF (OR (< answer 6)(> 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 an"
27. "example list"
28. ("example list" "1" 3 4 5 T)
29. "1"
30. (nth exampleList 4)
31. 4
32. ; error: bad argument type: consp nil
33. nil
34. T
35. "example list"
36. (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 Four
Definitions
Association 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 object’s 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 Questions
2. 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. ENTDEL
10. True
11. 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 input
18. ((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. 5
29. ((-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 arguments
32. ((-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)
(setq numberOne (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 (
21. 4
22. 4
23.
24. ; error: bad argument type: lentityp nil
25. ((-1 . ) (0 . "LINE") (330 . ) (5 . "2E") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbLine") (10 8.49744 7.10482 0.0) (11 4.65396 6.52041 0.0) (210 0.0 0.0 1.0))
26. C:CREATE_XRECORD ------( then ; error: bad argument type: lentityp nil
27. ; error: too few arguments
28. ((0 . "LAYER") (2 . "0") (70 . 0) (62 . 7) (6 . "Continuous"))
29. ; error: bad argument type: lentityp nil
30. ; error: bad xdata list:
31. (SETQ SelEntity (ENTSEL “\nSelect Line on Wall”))
(IF (/= SELENTITY Nil)
(PROGN
(REGAPP “BtuPerHour”)
(SETQ Exdata
(LIST
(LIST “BtuPerHour”
(CONS 1000 (STRCAT “The total
BTU/HR Heat loss is “
(RTOS BtuPerHour)
)
)
)
)
)
(SETQ NewEnt (APPEND SelEntity
(LIST (APPEND ‘(-3)
Exdata)
)
)
)
(ENTMOD NewEnt)
(PRINC)
32.
(DEFUN C:ChangeLayers()
(PRINC “\nSelect entity to change”)
(SETQ SelSet (SSGET)
EntSelected (ENTSEL)
)
(WHILE (> EntSelected Nil)
(SETQ EntSelected (ENTSEL))
)
(SETQ EntData (ENTGET (CAR EntSelected)
)
Layer (CDR (ASSOC 8 EntData)
)
(COMMAND “Chprop” SelSet “” “La” Layer “”) ;See Note
)
Note: The Bolded Text above can be replaced with the following section.
(SETQ Cnt 1
NewLayer (CONS 8 Layer)
)
(While (> SSLENGTH Cnt)
(SETQ EntName (SSNAME Selset (1- Cnt))
EntDataSel (ENTGET ENTGET EntName)
OldLayer (ASSOC 8 EntDataSel)
EntDataSel (SETQ EntDataSel (SUBST NewLayer
OldLayer EntDataSEl)
)
(ENTMOD EntDataSel)
(ENTUPD (CDR (ASSOC -1 EntDataSel)))
(Setq Cnt (1+ Cnt))
) ;End of While Loop
Chapter Six
Definitions
Attributes – An argument for a DCL tile. They are used in DCL to define a DCL tile function and layout.
AutoCAD PDF – AutoCAD Programmable Dialog Box Facility contains the predefined tiles used to construct a Diametric Dialog Box.
Boxed_column – Is identical to column in all respects except a border is created around the group of tiles.
Children – A set of controls or tiles that are contained within another set of controls or tiles.
Concatenation – A line of text made up of two or more concatenated text_part tiles. The purpose is to allow the programmer to supply a standard message to a dialog box that contains a portion that might be changed during runtime.
DCL – Dialog Control Language, a language used to construct dialog boxes inside of AutoCAD.
DIESEL – Direct Interpretively Evaluated String Expression Language, a language used to modify AutoCAD status bar.
Julian Date – A date format in which a real number is used to represent the current date. In Julian format the integer portion represents the number of days that have passed since the beginning of the first Julian Cycle, January 1, 4713 BC. The fractional portion represents the portion of a 24-hour day that has elapsed for the current Julian day.
Julian Time – Can be calculated using the formula using the formula (H + (M + S/60)/60)24
Prototypes – A custom tile used in a dialog. Prototypes are typically defined when the developer wants to keep a certain consistency among several different dialog boxes or when a particular arrangement of tiles is to be used over and over again in different dialog boxes.
Status Line – The lower region of the AutoCAD window used to display information concerning the current state of AutoCAD to the user.
Subassemblies – A grouping of tiles into rows and columns. Subassemblies can either be enclosed or not enclosed by a border.
Tree Structure – A phrase used to describe the relationship of the child/parent objects an/or tiles. Typically associated with the windows directory structure.
Parent – The main tile as object that contains one or more children.
Answers to Review Questions
2. DCL is used solely for the definition of dialog boxes whereas AutoLISP is used to develop applications that interface with or without dialog boxes.
3. Diesel is used solely for the customization of the AutoCAD status bar, whereas AutoLISP is used to develop applications that interface with or without dialog boxes.
4. Often the GUI interface is the only direct contact that the end user will have with an application. Therefore, if the interface is difficult to follow the user is more likely to not want to use the application.
5. The length of a string that can be passed to the MODEMACRO system cariable is limited by restrictions that are imposed by AutoLISP and the AutoLISP to AutoCAD communication buffer (255 characters).
6. MODEMACRO
7. True
8. False, DIESEL function can be nested within one another.
9. True
10. True
11. A custom tile used in a dialog. Prototypes are typically defined when the developer wants to keep a certain consistency among several different dialog boxes or when a particular arrangement of tiles is to be used over and over again in different dialog boxes.
12. To place a comment in a DCL file, the developer uses two forward slashes. When the comment is embedded within a line of DCL code it is separated from the code with a /* at the beginning of the comment and a */ at the end.
13. When supplied with a text string specifies the Key or tile that is Initially highlighted and therefore will be activated once the user presses enter.
14. A radio button is typically used by a programmer when it is necessary to limit the end user to only one possible selection from a group of options.
15. A list box is a component that is used to display text strings arranged in a vertical row. The list as well as the list box can be variable in length or a fixed length. A pop list when display at runtime will look similar to an edit box that has a downward pointing arrow displayed to its right.
16. User input can be entered into a dialog box by using either a edit box, toggles, radio buttons, buttons, image buttons, list boxes and popup list.
17. True
18. "This is an example or DIESEL"
[pic]
19. "Drawing Name = $(getvar, dwgname"
[pic]
20. "Drawing Name = ($getvar dwgname), Dim = $(getvar, dimstyle)"
[pic]
21.
[pic]
22. nil
23. 2.0001e+007
24. ; error: bad argument type: stringp 2.0001e+007
25.
[pic]
26. "M=\nCurrent Time : $(edtime, $(getvar, date), DDDD MONTH DD YYYY HH:MM:SS AM/PM)"
[pic]
27. "$(if, $(=, ans 1), The value of variable ans = 1"
[pic]
Chapter Seven
Definitions
Action Expression – Used to associate an AutoLISP expression with a specific tile definition in a dialog box.
Callback Function – Information regarding the action that the user has performed is returned to an action expression in the form of a callback function. Callback functions are most often used to update information within a dialog box.
Static – A tile doesn’t change from initialization to initialization.
Dynamic – A tile changes or can change from initialization to initialization.
Answers to Review Questions
2. Load the dialog box definition into memory, assign it an identification number, activate the dialog box, initialize its tiles, load images, specify the dialog boxes actions, verify the data entered, end the dialog sessions, extract the data entered and finally unload the dialog box’s definition.
3. If an error should occur when working with a nested dialog box. It is possible for control to not be reestablished to the parent dialog. At that point it may become necessary to terminate all current dialog boxes and return control to the AutoCAD command prompt.
4. DONE_DIALOG (done_dialog [status])
5. START_DIALOG
6. False, Control is redirected to the dialog box.
7. It is the identification number that is used whenever subsequent function calls are made to the dialog box.
8. Because some dialog boxes may contain custom tiles and/or standard tiles that have been redefined.
9. False, any calls to a SET_TILE function must be placed between the NEW_DIALOG and START_DIALOG function calls.
10. Start a list, then appends the entries to that list and finally close the list.
11. The creation of the image must be started, the image must then be defined and finally the creation process must be stopped.
12. Information regarding the action that the user has performed is returned to an action expression in the form of a callback function. Callback functions are most often used to update information within a dialog box.
13. Used to associate an AutoLISP expression with a specific tile definition in a dialog box.
14. By using the ACTION_TILE function. (action_tile key action-expression)
15. The initial value of a tile contained within a dialog box can be set using the DCL attribute VALUE. When this method is employed, the value assigned to a dialog box’s tiles is static and can not be changed from initialization to initialization or runtime. When the value of a tile is to change from initialization to initialization or runtime, then the AutoLISP SET_TILE function (set_tile key value) must be used.
16. False, It must be placed in an action expression or a callback function.
17. False, Activating a dialog box control function form either the AutoCAD command prompt or the Visual LISP Console window can cause AutoCAD to freeze up.
18. A screen capture of the AutoCAD graphic editor saved in a special format that can be viewed later from within AutoCAD.
19. A tile can be disabled either using the DCL attribute is_enabled of the AutoLISP function mode_tile. The is_enabled attribute is used for static conditions. Once this value is set the tile will remain disabled until the AutoLISP function MODE_TIEL is used to change the tile’s state.
20. If the dialog box has been unloaded from memory then the dialog must be reloaded, redefined and process used to display the dialog the first time reissued. However, if the dialog still resides in memory then a call to the START_DIALOG function will redispay the dialog box.
Chapter Eight
Definition
IDE – Integrated Development Environment, A development package that includes a fully integrated text editor, compiler, debugger and numerous other tools.
OOP – Object Oriented Programming,
API – Application Program Interface
Answers to Review Questions
2. False, Visual LISP is an extension of the AutoLISP programming language. It is considered the next evolutionary phase of the AutoLISP programming language.
3.
|Syntax Checker |File Compiler |Source Code Debugger |
|Text File Editor |AutoLISP Formatter |Comprehensive inspection and watch tools |
|Context-Senitive Help |Program Manager |Object Oriented Programming Concepts |
|ActiveX functions |Reactors | |
4. VLIDE for Versions 14.01 and 2000
VLISP for version 2000 only
5.
|Menus |Allows the developer to select Visual LISP commands |
|Toolbars |Allow the developer to select frequently used Visual LISP |
| |commands |
|Main Menu |Used to house the text editor, console window and debug window |
|Console Window |Designed to allow the developer to test and evaluate AutoLISP |
| |expressions |
|Trace Window |Designed to display the output of the trace function |
|Text Editor |A sophisticated programming tool integrated into a |
| |word-processing application specifically designed for the |
| |creation of AutoLISP programs. |
|Status Bar |Used to display the current state of the Visual LISP IDE. |
6. False, Toolbars are divided into five areas: Standard, Search, Tools, Debug and View.
7. False, The Visual LISP toolbars are shortcuts to frequently used Visual LISP commands.
8. CTRL + ALT + F
9. CTRL + SHIFT + F
10. It makes the source code easier to interrupt.
11. It allows the developer to rapidly identify the different components of the computer program by distinguishing the major components of an AutoLISP program.
12.
|Plain Style |Places all arguments on the same line separated by a mere space. This style is applied when the last |
| |character of an expression does not exceed the right margin – the value of the approximate line length |
| |environment is free of embed comments with new line characters. |
|Wide Style |Arranges arguments so that the first argument is contained on the same line as the function. Any remaining |
| |arguments associated with the function are place in a column directly below the first argument. This style |
| |is applied when the Plane style cannot be employed and the first element is a symbol whose length is less |
| |than the maximum wide style car length environment option. |
|Narrow Style |Places the first argument on the line following the function with all remaining arguments arranged in a |
| |column positioned below the first argument. This style is applied when the Plane and Wide Styles cannot be |
| |used. This style is also applied to all PROGN expressions. |
|Column Style |Formats the code so that all elements are placed in a column. This style is used for quoted list and all |
| |CONS expressions. The formatter chooses the correct style to apply according to the rules established by |
| |the format options dialog box. |
13. Allows the developer to keep track of parenthesis used to group expressions and functions together.
14. CTRL + ]
15. False, To display the value of a variable in the console window only the variables’ name is required at the console window’s command prompt.
16. False, Multiple searches can be performed in Visual LISP.
17. Bookmarkers are non-printable character that are used as anchors that allow the developer to review a particular section of an application without scrolling through all the source code.
18. CTRL + COMMA
19. CTRL + SPACEBAR
20. Is the mechanism used be Visual LISP to keep track of all symbol used by AutoLISP.
21. By pressing CTRL + SHIFT + SPACEBAR
22. It allows the developer to monitor the value of a variable during a program execution.
23. Visual LISP inspection tools allow the developer to navigate, view and modify both AutoLISP and AutoCAD object.
24. It is a historical record of the execution of expressions and functions that have been evaluated during the execution of an AutoLISP application. The stack is used by AutoLISP as a means of remembering it way out of nested functions.
25. When an error occurs in an application the content of the stack are flushed. To retain a copy of the trace stack when a program crashes the contents can be written out to the debug window using the error trace stack (Error Trace) feature.
26. False, Visual LISP provides four different browsers for viewing the contents of the AutoCAD database.
27. A project is nothing more than a list of AutoLISP source code files that are associated with a particular application and a set of rules as to how those files are to be compiled.
28.
|FAX |Compiled AutoLISP programs. |
|VLX |Standalone AutoCAD applications. |
|PRJ |Contains the location and names of all source files that build the project - as well as certain parameters and rules|
| |on how to compile the project. |
29. Compiled applications execute faster than non-compiled applications. Also the developer is able to hide their source code from end user, thereby giving the developer a means of security.
30. This option instructs the AutoLISP compiler to refuse optimizing the source code if there is a chance that doing so could produce an incorrect FAS file.
Chapter Nine
Definitions
Object Oriented Programming – a method of programming in which the actual data used by an application is the major concern instead of the actual process involved to manipulate the data.
ActiveX - Is an outgrowth of two other Microsoft technologies called OLE (Object Linking and Embedding) and COM (Component Object Model).
Event Driven Programming – A program remains idle until the operator performs some action that triggers an event, such as moving a mouse, or pressing a button.
Structured Programming – A method of programming in which all programs are assumed to be interpreted by the computer starting from the beginning of the application and proceeding until it reaches the end. Statements and expressions are executed one after the other following the order in which they are presented.
Class – Is a template used to create an object. Classes are groups of relate objects that share common properties and methods.
Object – Is an individual member of a class or an instance of that class. Objects consists of two primary parts, the properties and methods.
Method – Are the procedures or function used to manipulate the data associated with an object.
Properties – The information regarding the characteristics of an object.
Data – Information consisting of character, number, images, etc. used by a computer program for processing.
Spaghetti Programming – A method of programming in which programs are not written to a set standard, thereby producing applications that are unreliable and difficult to maintain.
Array –
Safe Array –
Encapsulation – a method of ensuring the integrity of an object’s properties from unauthorized or even inappropriate access by letting the object control how data associated with the object is accessed.
Polymorphism – Is when a program treats different objects as if they were identical and each object reacts as it was originally intended.
Object Linking and Embedding – was intended as a means of creating compound documents.
Compound Object Modeling – COM (compound object modeling) provided a means of establishing interaction between software libraries, applications, system software, etc. COM does this by defining a standard by which applications can communicate with one another.
Parent Object – The original object in which an object is created from.
Child Object – An object that is created from other objects.
Inspection Tool – A Visual LISP tool that is used to examine the properties of an object.
Visual Basic – A programming Language developed by Microsoft for the rapid development of Windows based applications.
Visual Basic Application – A version of Visual Basic designed to allow a programmer to develop programs designed for specific applications (Word, Excel, PowerPoint, AutoCAD, etc.).
Variant – Is a variable that can contain different data types.
Wrapper Function – Is a standard function that encapsulates the code used by the application object (the VLA functions in Visual LISP are merely wrapper functions created from the AutoCAD type library)
Collection - Is a grouping of all related AutoCAD objects into categories.
Answers to Review Questions
2. After a wrapper function has been created Visual LISP’s Apropos feature can be used to list the ActiveX wrapper functions that have been.
3. In AutoLISP this is done by using the vlax-import-type-library (vlax-import-type-library :tlb-filename filename [ :methods-prefix mprefix :properties-prefix pprefix :constants-prefix cprefix])function.
4. The vlax-invoke-method function provides the developer with a means of calling ActiveX methods
5. Structured programming allowed the developer to create applications in a modular fashion, meaning that the program is broken up into manageable portions. Each portion was defined as a subroutine that can be called by the main program. Structured programming also provided the developer with an avenue for making decisions based upon information that has been tested against a specific condition. Finally, structured programming introduced the concept of loops.
6.
7. The methods are the procedures or functions used to manipulate the data associated with an object. To access the methods associated with an object created by an application other than AutoCAD, the vlax-invoke-method function should be used.
8. ActiveX is a COM based technology.
9. The vlax-get-object function establishes a connection to a currently running instance of an external application. If the application is not currently running or if the vlax-get-object function should return nil, then a connection to the specified application can be created through the AutoLISP function vla-create-object. This function creates a new instance of the target application object, after which it creates a connection to the instance.
10. False, the VLAX-GET-OBJECT just tries to establish a connection where as the VLAX-GET-OR-CREATE-OBJECT attempts to make a connection to the specified application object. If the connection cannot be established, then the function creates an instance of the application and then establishes a connection.
11. False, AutoCAD is an integral part of the AutoLISP programming language and therefore AutoCAD must be running.
12. False, The VL-LOAD-COM function must be loaded before ActiveX controls can be used in an AutoLISP application.
13. By either importing the application’s type library or using AutoLISP to make direct contact with that object’s methods, properties, or constants. When an object’s type library is imported into Visual LISP, AutoCAD automatically generates a set of wrapper functions for the imported features. Once the application object’s library has been imported into Visual LISP, then the wrapper function created can be accessed by the AutoLISP application and Visual LISP’s symbol features. Importing an applications object’s library can be beneficial to the developer; however, it can also have a dramatic impact on the application being developed by incorporating unnecessary methods, properties, and constants, thus adding to the amount of memory required by the application. To circumvent the adverse affects of loading an entire application object’s library, AutoLISP has three functions that allow the developer to access an application’s object without loading the application’s object library. They are vlax-invoke-method (vlax-invoke-method obj method arg [arg...]), vlax-get-property (vlax-get-property object property), and vlax-put-property (vlax-put-property obj property arg).
14. It frees valuable memory.
15. True
16. False, The vlax-import-type-library function allows the developer to specify the prefixes to append to the object’s methods, properties, and constants.
17. True
18. True
19.
(vl-load-com)
(SETQ application (VLAX-GET-ACAD-OBJECT)
;assigns a pointer to the AutoCAD Application
document (VLA-GET-ACTIVEDOCUMENT application)
;Connects to the current active document
modelspace (VLA-GET-MODELSPACE document)
)
20.
(vl-load-com)
(if (equal nil MS-Wordc-wd100Words)
(vlax-import-type-library
:tlb-filename
"C:\\Program Files\\Microsoft Office\\Office\\msword8.olb"
:methods-prefix
"MS-Wordm-"
:properties-prefix
"MS-Wordp-"
:constants-prefix
"MS-Wordc-"
)
)
21.
;;;********************************************************************
;;;
;;; Program Name: VL05.lsp
;;;
;;; Program Purpose: This program allows the user to construct a
;;; simple gear train, from the Pinion Gear RPM,
;;; the gear ratio, the diametral pitch, shaft
;;; diameter, and number of teeth on the pinion
;;; gear. The two gears are constructed as blocks,
;;; and the rpms, number of teeth and gear ratio
;;; of both gears are saved to the newly constructed
;;; entities in the form of extended entity data.
;;;
;;; Program Date: 2/31/99
;;;
;;; Written By: James Kevin Standiford
;;;
;;;********************************************************************
;;;********************************************************************
;;;
;;; Main Program
;;;
;;;********************************************************************
(DEFUN c:gear (/ rpm number_teeth
gear_ratio dia_pitch shaft_dia PT
pitch_dia gear_teeth gear_out Pinion_out
gear_rpm dist pt_x pt_y
pinion gear shaft_pinion
Shaft_gear lastent exdata1 newent1
exdata newent
)
(vl-load-com)
(SETQ application (VLAX-GET-ACAD-OBJECT)
document (VLA-GET-ACTIVEDOCUMENT application)
modelspace (VLA-GET-MODELSPACE document)
rpm (GETREAL "\nEnter RPM of Pinion Gear : ")
number_teeth (GETREAL "\nEnter Number of Teeth : ")
gear_ratio (/ 1 (GETREAL "\nEnter Gear Ratio : "))
dia_pitch (GETREAL "\nEnter Diametral Pitch : ")
shaft_dia (GETREAL "\nEnter Shaft Diameter : ")
PT (GETPOINT "\nSelect Point : ")
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; Calculates the pitch diameter, number of teeth on the gear,
;;; the outside diameter of the gear the outside diameter of the
;;; pinion, the distance between the pinion and the gear and the
;;; position of the gear
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pitch_dia (/ number_teeth dia_pitch)
gear_teeth (* gear_ratio number_teeth)
gear_out (+ pitch_dia (* 2 (/ 1 (/ gear_teeth pitch_dia))))
pinion_out (+ pitch_dia (* 2 (/ 1 (/ number_teeth pitch_dia))))
gear_rpm (* gear_ratio rpm)
dist (+ (* 0.5 pinion_out) (* 0.5 gear_out))
pt_x (+ dist (CAR pt))
pt_y (CADR pt)
)
;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; Begins the construction of the pinion block
;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(VLA-ADDCIRCLE
modelspace
(VLAX-3d-Point pt)
(/ pinion_out 2)
)
(setq lastent (entget (entlast)))
;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;;;;; Modifies the entity created by attaching XDATA
;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(regapp "pinion")
(setq exdata1
(LIST
(LIST "pinion"
(CONS 1000 (STRCAT "Pinion's RPM " (RTOS rpm)))
(CONS 1041 gear_ratio)
(CONS 1042 number_teeth)
)
)
)
(setq newent1
(append lastent (list (append '(-3) exdata1)))
)
(entmod newent1)
(VLA-ADDCIRCLE
modelspace
(VLAX-3d-Point (LIST pt_x pt_y))
(/ gear_out 2.0)
)
;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;;;;; Modifies the entity created by attaching XDATA
;;;;;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(setq lastent (entget (entlast)))
(regapp "gear")
(setq exdata
(LIST
(LIST "gear"
(CONS 1000 (STRCAT "Mating Gear's RPM " (RTOS rpm)))
(CONS 1041 gear_ratio)
(CONS 1042 gear_teeth)
)
)
)
(setq newent
(append lastent (list (append '(-3) exdata)))
)
(entmod newent)
(VLA-ADDCIRCLE
modelspace
(VLAX-3d-Point pt)
(/ shaft_dia 2.0)
)
(VLA-ADDCIRCLE
modelspace
(VLAX-3d-Point (LIST pt_x pt_y))
(/ shaft_dia 2.0)
)
(princ)
)
22.
;;;*******************************************************************
;;; Program Name: ActiveXSeries.lsp
;;; Program Purpose: Calculate the voltage drop for a group of
;;; resistors, equivalent resistance,
;;; Total Current
;;;
;;; Programmed By: James Kevin Standiford
;;; Date: 3/21/2000
;;;********************************************************************
(defun c:series (/ volt l_length)
(setvar "cmdecho" 0)
;;;***~~~~~~New~~~~~~***~~~~~~~NEW~~~~~~~~***~~~~~~~~NEW~~~~~~
(vl-load-com)
(if (equal nil MS-Wordc-wd100Words)
(vlax-import-type-library
:tlb-filename
"C:\\Program Files\\Microsoft Office\\Office\\msword8.olb"
:methods-prefix
"MS-Wordm-"
:properties-prefix
"MS-Wordp-"
:constants-prefix
"MS-Wordc-"
)
)
(setq MS-Word (vlax-get-or-create-object "Word.Application.8"))
(vla-put-visible MS-Word :vlax-true)
(setq documents (vla-get-documents MS-Word)
new-document (MS-Wordm-add documents)
paragraphs (MS-Wordp-get-paragraphs new-document)
page (MS-Wordp-get-last paragraphs)
range (MS-Wordp-get-range page)
res (ssget "x" (list (cons 0 "insert") (cons 2 "resistor")))
)
;;;***~~END New~~~~~~***~~~END NEW~~~~~~~~***~~~~END NEW~~~~~~
(if (/= res nil)
(progn
(setq rcnt 0
volt (getreal "\nEnter voltage : ")
l_length (sslength res)
ent (entget
(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))
)
r_list (list (atof (cdr (assoc 1 ent))))
ent_name_list (list
(cdr
(assoc -1
(entget (entnext (cdr (assoc -1 ent))))
)
)
)
r_num
(list
(cdr
(assoc
1
(entget
(entnext
(cdr
(assoc
-1
(entget (entnext (cdr (assoc -1 ent)))
)
)
)
)
)
)
)
)
rcnt (1+ rcnt)
)
(while (< rcnt l_length)
(setq
ent (entget
(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))
)
r_list
(append r_list
(list (atof (cdr (assoc 1 ent))))
)
ent_name_list
(append
ent_name_list
(list (cdr
(assoc
-1
(entget (entnext (cdr (assoc -1 ent)))
)
)
)
)
)
r_num
(append
r_num
(list
(cdr
(assoc
1
(entget
(entnext
(cdr (assoc
-1
(entget
(entnext
(cdr (assoc -1 ent))
)
)
)
)
)
)
)
)
)
)
rcnt (1+ rcnt)
)
)
(setq list_cnt (- (length r_list) 1)
eq_res
(nth 0 r_list)
l_cnt 1
)
(while (vla-object
(cdr (assoc -1 (entget (car (entsel)))))
)
)
"Example Line Reactor"
'((:vlr-Erased . ModifySeries))
)
)
)
;;;************
;;; CallBack Function
;;;************
(defun ModifySeries (notifier reactor parameter)
(vl-load-com)
(AutoSeries)
)
)
;;;*************
;;; AutoSeries program
;;;*************
(defun c:series ()
(AutoSeries)
)
(defun AutoSeries(/ volt l_length)
(setvar "cmdecho" 0)
(setq res (ssget "x" (list (cons 0 "insert") (cons 2 "resistor")))
)
(if (/= res nil)
(progn
(setq rcnt 0
volt (getreal "\nEnter voltage : ")
l_length (sslength res)
ent (entget
(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))
)
r_list (list (atof (cdr (assoc 1 ent))))
ent_name_list (list
(cdr
(assoc -1
(entget (entnext (cdr (assoc -1 ent))))
)
)
)
r_num
(list
(cdr
(assoc
1
(entget
(entnext
(cdr
(assoc
-1
(entget (entnext (cdr (assoc -1 ent)))
)
)
)
)
)
)
)
)
rcnt (1+ rcnt)
)
(while (< rcnt l_length)
(setq
ent (entget
(entnext (cdr (assoc -1 (entget (ssname res rcnt)))))
)
r_list
(append r_list
(list (atof (cdr (assoc 1 ent))))
)
ent_name_list
(append
ent_name_list
(list (cdr
(assoc
-1
(entget (entnext (cdr (assoc -1 ent)))
)
)
)
)
)
r_num
(append
r_num
(list
(cdr
(assoc
1
(entget
(entnext
(cdr (assoc
-1
(entget
(entnext
(cdr (assoc -1 ent))
)
)
)
)
)
)
)
)
)
)
rcnt (1+ rcnt)
)
)
(setq list_cnt (- (length r_list) 1)
eq_res
(nth 0 r_list)
l_cnt 1
)
(while ( ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- all data everywhere
- hl7 version 2 5 1 implementation guide immunization
- experiments in software watermarking university of
- table of contents
- entertitlehere training manual
- jaws 4 accessing higher ground
- chemistry enhanced scope sequence
- writing four part chorale form with roman numerals and
- identify gfebs master data elements
- chapter three
Related searches
- three functions of managerial finance
- chapter three psychology test
- chapter by chapter bible summary
- chapter three research methodology sample
- three by three matrix solver
- chapter by chapter summaries
- novel outline template chapter by chapter pdf
- chapter 9 chapter review answers
- outsiders chapter summary chapter 5
- genesis chapter by chapter summary
- solving three equations with three unknowns
- chapter by chapter bible study