Download Instructor`s Manual

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Falcon (programming language) wikipedia , lookup

Immunity-aware programming wikipedia , lookup

TI-BASIC wikipedia , lookup

Transcript
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
Start
Material
Thickness
Bend Radius
Bend Angle
Calculations
Print Results
End
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
*PRINC
*PRINT
*WRITE-LINE
Prints an expression to the command line
or writes an expression to an open file
Prints an expression to the command line
or writes an expression to an open file
Prints an expression to the command line
or writes an expression to an open file
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
)
Returns
3.14
9.99 TEXT1 TEXT2 9.11 RED MONDAY)
(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 . <Entity name: 1583d58>) (0 . "LINE") (330 . <Entity name: 1583cf8>) (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. <Entity name: 1583d78>
21. ((-1 . <Entity name: 1583d78>) (0 . "LINE") (330 . <Entity name: 1583cf8>) (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. <Entity name: 1583d58>
23. ((-1 . <Entity name: 1583d58>) (0 . "LINE") (330 . <Entity name: 1583cf8>) (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. <Entity name: 1583d78>
25. ("this is an example" "list")
26. ("this is an example" "list")
27. <Entity name: 15a4160>
28. 5
29. ((-1 . <Entity name: 15a4160>) (0 . "LINE") (330 . <Entity name: 15a40f8>) (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 . <Entity name: 15a4160>) (0 . "LINE") (330 . <Entity name: 15a40f8>) (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 . <Entity name: 15a4160>) (0 . "LINE") (330 .
<Entity name: 15a40f8>) (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. <Entity name: 15a4160>
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 (<= 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
1
TotalRFactor 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)) “LINE”)
(PROGN
(SETQ PointOne (GETPOINT “\nSelect first
point of Line”)
PointTwo (GETPOINT “\nSelect second
point of line”)
PointOne (CONS 10 PointOne)
PointTwo (CONS 11 PointTwo)
Ent (SUBST PointOne (Assoc 10 ent) ent)
Ent (SUBST PointTwo (Assoc 10 ent) ent)
)
(ENTMOD Ent)
(ENTUPD (CAR Ent))
)
(ALERT “A line must be selected”)
)
)
(ALERT “Nothing Selected”)
)
)
39.
(DEFUN c:CalculateBtu()
(SETQ Cnt
1
TotalRFactor 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)
)
)
;**********************************************
;
;
;
New Section for writing Result to either the screen
;
or an ASCII Text file.
;
;
;**********************************************
(SETQ Answer (GETSTRING “\nWrite results to either a <F>ile or <G>raphic
screen : “)
)
(IF (OR (= Answer “F”) (= Answer “f”)
(PROGN
(SETQ File1 (OPEN “OutPut.Txt” “w”))
(Write-Line BtuPerHour File1)
(Close file1)
)
(PROGN
(PRINC (STRCAT “\nThe total btu per hour heat loss is “
(RTOS BtuPerHour)
)
)
(PRINC)
)
)
Chapter Five
Definitions
Symbol Table – is similar to a filing cabinet for AutoCAD in the respects that it is used to
store information regarding non-graphic (Layers, Linetypeas, Styles, Viewports, Views,
Dimension Styles, User Coordinates Systems and Applications).
Application Identification Table – A table used by AutoCAD to store the names of all
applications that have been registered in an AutoCAD drawing.
Application Name – In AutoCAD all extended entity data must be assigned an
application name. The application name can only be used once in a drawing. This helps
ensure that information assigned by more than one program to the same AutroCAD entity
is unique.
Dictionary – Is similar in concept to a symbol table, however the dictionary is used to
store non-graphic information that cannot be contained within a symbol table.
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.
Filters – Allows the developer to perform either a broad or narrow asearch of a drawing’s
database.
Answers to Review Questions
2. See above
3. (REGAPP “VisualLisp”)
The REGAPP function when supplied with an application name, first checks the
APPID table to determine if the application name is already in use. If the application
name is not in use, then the function adds the name to the table and returns the name
that was added. If the application name already exist, then the function returns NIL.
4. See Above
5. (SETQ Ans (TBLSEARCH “Appid” “VisualLISPExample”))
(IF (/= Ans Nil)
(REGAPP “VisualLispExample”)
(PRINC “\nApplication is already registered”)
)
6. False, The ENTMOD function can be used to modify extended entity data.
7. True
8. Extended Entity Data is designed to allow the developer to store non AutoCAD
information in an object’s association list by using DXF codes.
Extended Entity Data is an extension of an object’s association list. In it’s native form an
entity association list will only contain relevant AutoCAD information.
9. SSGET
(SETQ SelectionOne (SSGET “X”))
10. The TBLSEARCH function searches a symbol table for a specific entity name, where
as the TBLNEXT, function when supplied with a valid sub-table name returns the next
entity residing in that table.
11. <Selection set: 5>
12. <Selection set: 7>
13. <Selection set: 9>
14. ; error: bad point argument
15. <Selection set: b>
16. <Selection set: d>
17. <Selection set: f>
18. <Selection set: 11>
19. <Selection set: 13>
20. (_>
21. 4
22. 4
23. <Entity name: 1583d70>
24. ; error: bad argument type: lentityp nil
25. ((-1 . <Entity name: 1583d70>) (0 . "LINE") (330 . <Entity name: 1583cf8>) (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: <Entity name: 1583d58>
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"
19. "Drawing Name = $(getvar, dwgname"
20. "Drawing Name = ($getvar dwgname), Dim = $(getvar, dimstyle)"
21.
22. nil
23. 2.0001e+007
24. ; error: bad argument type: stringp 2.0001e+007
25.
26. "M=\nCurrent Time : $(edtime, $(getvar, date), DDDD MONTH DD YYYY
HH:MM:SS AM/PM)"
27. "$(if, $(=, ans 1), The value of variable ans = 1"
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
Text File Editor
File Compiler
AutoLISP Formatter
Context-Senitive Help
Program Manager
ActiveX functions
Reactors
Source Code Debugger
Comprehensive inspection
and watch tools
Object Oriented
Programming Concepts
4. VLIDE for Versions 14.01 and 2000
VLISP for version 2000 only
5.
Menus
Toolbars
Main Menu
Console Window
Trace Window
Text Editor
Allows the developer to select Visual LISP
commands
Allow the developer to select frequently
used Visual LISP commands
Used to house the text editor, console
window and debug window
Designed to allow the developer to test and
evaluate AutoLISP expressions
Designed to display the output of the trace
function
A sophisticated programming tool
integrated into a word-processing
Status Bar
application specifically designed for the
creation of AutoLISP programs.
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
VLX
PRJ
Compiled AutoLISP programs.
Standalone AutoCAD applications.
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-typelibrary :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
l_cnt
(nth 0 r_list)
1
)
(while (<= l_cnt list_cnt)
(setq resistor (nth l_cnt r_list))
(if (/= resistor nil)
(setq eq_res
(+ eq_res resistor)
)
)
(setq l_cnt (1+ l_cnt))
)
(setq name (GETVAR "dwgname")
length_string (STRLEN name)
name_truncated (SUBSTR name 1 (- length_string 3))
result_file
(open (STRCAT (getvar "dwgprefix")
name_truncated
".RLT"
)
"a"
)
amperage
(/ volt eq_res)
)
(princ "\n" result_file)
(setq string
(strcat
(princ
(strcat
"\nThe equivalent resistance for the circuit on Drawing : "
(getvar "dwgname")
" is "
(rtos eq_res)
" ohms"
)
result_file
)
(princ
(strcat "\nThe voltage for this circuit is " (rtos volt))
result_file
)
(princ (strcat "\nThe total current for this circuit is "
(rtos amperage)
" amps"
)
result_file
)
)
)
(setq l_cnt 0)
(while (<= l_cnt list_cnt)
(setq
string (strcat
string
(princ (strcat
"\nThe voltage drop for resistor "
(nth l_cnt r_num)
" is "
(setq g (rtos (* (nth l_cnt r_list)
amperage
)
)
)
;;;~~~~~~~~~~~~NEW~~~~~~~~~~~~~~~~NEW~~~~~~~~~~~~~~~NEW~~~~~~~~
" volts it resistance is "
(rtos (nth l_cnt r_list))
" OHMS The Current for this resistor is "
(RTOS amperage)
" AMPS"
;;;~~~~~~~END~~NEW~~~~~~~~~~~END~~NEW~~~~~~~~~~END~~NEW~~~~~
)
result_file
)
)
)
(setq resistor_ent (nth l_cnt ent_name_list)
entg
(entget resistor_ent)
entg
(subst (cons 1 g) (assoc 1 (entget resistor_ent)) entg)
)
(entupd (cdr (assoc -1 (entmod entg))))
(setq l_cnt (1+ l_cnt))
)
;;;***~~~~~~New~~~~~~***~~~~~~~NEW~~~~~~~~***~~~~~~~~NEW~~~~~~
(MS-Wordm-InsertAfter range string)
;;;***~~END New~~~~~~***~~~END NEW~~~~~~~~***~~~~END NEW~~~~~~
(alert string)
(close result_file)
(command "modemacro"
(strcat "The voltage used for this circuit was "
(rtos volt)
" volts"
)
)
(princ)
)
)
(if (= res nil)
(alert "No Resistors Found : ")
)
(princ)
)
(princ "\nEnter series to start program :")
(princ)
Chapter Ten
Definitions
*VLR-Toolbar-Reactor - Constructs an editor reactor object that notifies of a change to
the bitmaps in a toolbar
*:VLR-Undo-Reactor - Constructs an editor reactor object that notifies of an undo even
*:VLR-Wblock-Reactor - Constructs an editor reactor object that notifies of an event
related to writing a block
*:VLR-Window-Reactor - Constructs an editor reactor object that notifies of an event
related to moving or sizing an AutoCAD window
*:VLR-XREF-Reactor - Constructs an editor reactor object that notifies of an event
related to attaching or modifying XREFs
*:VLR-AcDb-Reactor - Constructs a reactor object that notifies when an object is added
to, modified in, or erased from a drawing database
*:VLR-Command-Reactor - Constructs an editor reactor that notifies of a command
event
*:VLR-DeepClone-Reactor - Constructs an editor reactor object that notifies of a deep
clone event
*:VLR-DocManager-Reactor - Constructs a reactor object that notifies of events relating
to drawing-documents
*:VLR-DXF-Reactor - Constructs an editor reactor object that notifies of an event related
to reading or writing a DXF file
*:VLR-Editor-Reactor - Constructs an editor reactor object
*:VLR-Insert-Reactor - Constructs an editor reactor object that notifies of an event
related to block insertion
*:VLR-Linker-Reactor - Constructs a reactor object that notifies your application every
time an ObjectARX application is loaded or unloaded
*:VLR-Lisp-Reactor - Constructs an editor reactor object that notifies of a LISP event
*:VLR-Miscellaneous-Reactor - Constructs an editor reactor object that does not fall
under any other editor reactor types
*:VLR-Mouse-Reactor - Constructs an editor reactor object that notifies of a mouse event
(for example, a double-click)
*:VLR-Object-Reactor - Constructs an object reactor object
*:VLR-SysVar-Reactor - Constructs an editor reactor object that notifies of a change to a
system variable
Callback Events - The events associated with a reactor type.
Database Reactors - An event that performs a generic change to the AutoCAD drawing
database.
Document Reactors - When the user changes the status of a document (drawing) then a
Document Reactor can be used to notify the application that such an event has occurred.
Editor Reactors - When the user activates an AutoCAD command or activates an
AutoLISP application, then an Editor Reactor can be used to notify an application that a
command has been issued.
Linker Reactors - AutoCAD also provides a means of notifying an application whenever
an ObjectARX application has been loaded and/or unloaded by using Linker Reactor
identifier.
Object Reactors - Object reactors notify an application whenever a specific object in the
database has been changed, copied, deleted or modified in any way.
Reactor - Is an object that is attached to an AutoCAD drawing entity for the express
purposes of having AutoCAD contact an application when a specified event occurs.
*VL-LOAD-COM - Loads Visual LISP extensions to AutoLISP
Note: All definitions starting with a * were taken from the AutoLISP Programmers
Reference.
Answers to Review Questions
2.
Database Reactors
Document Reactors
Editor Reactors
Linker Reactors
Object Reactors
3. When a reactor is to be confined to an entity, an object reactor must be constructed.
Object reactors are unlike AutoCAD reactors in that the reactor itself is attached to a
specific object.
4. Callback functions for reactors are a standard AutoLISP application defined by the
DEFUN function.
5. VLAX-ENAME->VLA-OBJECT
6. False, AutoLISP can be used to modify a reactor’s definition data.
7. By using the VLR-PERS (vlr-pers reactor) function
8. By using the VLR-NOTIFICATON (vlr-notification reactor) function.
9. False, Because reactors use the extended AutoLISP functions provided in Visual LISP,
the supporting code that enables reactor calls must first be loaded.
10. True, However, a Reactor can be disabled using the AutoLISP VLR-REMOVE
(vlr-remove reactor) function.
11. A list of VLA-Objects to be associated with that particular reactor.
12.
;;;**********
;;;
Defining the Reactor Function
;;;**********
(defun c:define_reactor
()
(vl-load-com)
(setq vlr-object
(vlr-object-reactor
(list (vlax-ename->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 (<= l_cnt list_cnt)
(setq resistor (nth l_cnt r_list))
(if (/= resistor nil)
(setq eq_res
(+ eq_res resistor)
)
)
(setq l_cnt (1+ l_cnt))
)
(setq name (GETVAR "dwgname")
length_string (STRLEN name)
name_truncated (SUBSTR name 1 (- length_string 3))
result_file
(open (STRCAT (getvar "dwgprefix")
name_truncated
".RLT"
)
"a"
)
amperage
(/ volt eq_res)
)
(princ "\n" result_file)
(setq string
(strcat
(princ (strcat
"\nThe equilivent resistance for this circuit is "
(rtos eq_res)
" ohms"
)
result_file
)
(princ
(strcat "\nThe voltage for this circuit is " (rtos volt))
result_file
)
(princ (strcat "\nThe total current for this circuit is "
(rtos amperage)
" amps"
)
result_file
)
)
)
(setq l_cnt 0)
(while (<= l_cnt list_cnt)
(setq
string (strcat
string
(princ (strcat
"\nThe voltage drop for resistor "
(nth l_cnt r_num)
" is "
(setq g (rtos (* (nth l_cnt r_list)
amperage
)
)
)
" volts"
)
result_file
)
)
)
(setq resistor_ent (nth l_cnt ent_name_list)
entg
(entget resistor_ent)
entg
(subst (cons 1 g) (assoc 1 (entget resistor_ent)) entg)
)
(entupd (cdr (assoc -1 (entmod entg))))
(setq l_cnt (1+ l_cnt))
)
(alert string)
(close result_file)
(command "modemacro"
(strcat "The voltage used for this circuit was "
(rtos volt)
" volts"
)
)
(princ)
)
)
(if (= res nil)
(alert "No Resistors Found : ")
)
(princ)
)
(princ "\nEnter series to start program :")
(princ)
13.
;;;**********
;;;
CallBack Function
;;;**********
(defun c:define_reactor
()
(vl-load-com)
(setq vlr-object
((vlr-insert-reactor
(list (vlax-ename->vla-object
(cdr (assoc -1 (entget (car (entsel)))))
)
)
"Example Line Reactor"
'((:vlr-endInsert . ModifySeries))
)
)
)
14.
;;;*******************************************
;;;
Define Reactor
;;;*******************************************
(defun c:define_reactor
()
(vl-load-com)
(setq vlr-object
((vlr-insert-reactor
(list (vlax-ename->vla-object
(cdr (assoc -1 (entget (car (entsel)))))
)
)
"Example Line Reactor"
'((:vlr-Erased . ModGearReactor))
)
)
)
;;;*******************************************
;;;
CallBack Function
;;;*******************************************
(defun ModGearReactor (notifier reactor parameter)
(vl-load-com)
(GearReactor)
)
)
;;;**********
;;;
Gear Train program
;;;**********
(DEFUN c:gear ()
GearProgram)
)
(DEFUN GearReactor()
(setq answer (getString "\nDo you want to rerun the gear program now : ")
)
(if (or (= answer "Y")(= answer "y"))
(GearPogram)
)
)
(DEFUN GearProgram()
(SETQ
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 : ")
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)
disatance (+ (* 0.5 pinion_out) (* 0.5 gear_out))
pt_x
(+ disatance (CAR pt))
pt_y
(CADR pt)
pinion
(LIST (CONS 0 "CIRCLE")
(CONS 10 pt)
(CONS 40 (/ pinion_out 2))
(CONS 8 "pinion")
)
(LIST (CONS 0 "CIRCLE")
(CONS 10 (LIST pt_x pt_y))
(CONS 40 (/ gear_out 2.0))
(CONS 8 "gear")
)
shaft_pinion (LIST (CONS 0 "CIRCLE")
(CONS 10 pt)
(CONS 40 (/ shaft_dia 2.0))
(CONS 8 "pinion")
)
shaft_gear (LIST (CONS 0 "CIRCLE")
(CONS 10 (LIST pt_x pt_y))
(CONS 40 (/ shaft_dia 2.0))
(CONS 8 "pinion")
)
gear
)
(ENTMAKE (list (cons 0 "block")
(CONS 2 "pinion")
(cons 10 (LIST pt_x pt_y))
(cons 70 64)
)
)
(ENTMAKE pinion)
(ENTMAKE shaft_pinion)
(ENTMAKE (list (cons 0 "endblk")))
(ENTMAKE (list (CONS 0 "INSERT")
(cons 2 "pinion")
(cons 10 (LIST pt_x pt_y))
)
)
(setq lastent (entget (entlast)))
(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)
(ENTMAKE (list (cons 0 "block")
(CONS 2 "gear")
(cons 10 (LIST pt_x pt_y))
(cons 70 64)
)
)
(ENTMAKE gear)
(ENTMAKE shaft_gear)
(ENTMAKE (list (cons 0 "endblk")))
(ENTMAKE (list (CONS 0 "INSERT")
(cons 2 "gear")
(cons 10 (LIST pt_x pt_y))
)
)
(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)
(princ)
)
15.
(defun known (reactor knowncommand_info)
(vl-load-com)
(SETQ Fil (OPEN "AutoCADOutPut.TXT" "a"))
(WRITE-LINE (car knowncommand_info) Fil)
(princ)
(close Fil)
)
(VLR-EDITOR-REACTOR nil '((:vlr-commandEnded . known)))
Chapter Eleven
Definitions
Blackboard- A blackboard is a NameSpace that is separate from documents and VLX
applications. Its purpose is to provide documents and applications with a means of
sharing data between NameSpaces
Error Trapping – are user-defined functions that are created using the DEFUN function.
Their purpose is to convey to the user information about the condition that caused the
error to occur, restore the AutoCAD environment to a known condition, and continue
program execution.
MDI – Multiple Document Interface
NameSpace – Is a LISP environment that contains an isolated set of symbols (variables
and functions). Each open drawing has it own unique NameSpace. Variables and
functions defined in one NameSpace are isolated from variables and functions defined in
another.
SDI – Single Document Interface
*VL-ARX-IMPORT – Imports ObjectARX/ADSRX functions into a separate-namespace
VLX
*VL-DOC-EXPORT – Makes a function available to the current document
*VL-DOC-IMPORT – Imports a previously exported function into a VLX namespace
*VL-DOC-REF – Retrieves the value of a variable from the current document's
namespace.
*VL-DOC-SET – Sets the value of a variable in the current document's namespace.
*VL-EXIT-WITH-ERROR – Passes control from a VLX error handler to the *error*
function of the calling namespace
*VL-EXIT-WITH-VALUE – Returns a value to the function that invoked the VLX from
another namespace
*VL-LIST-EXPORTED-FUNCTIONS – Lists exported functions
*VL-LIST-LOADED-VLX – Returns a list of all separate-namespace VLX files
associated with the current document.
*VL-UNLOAD-VLX – Unload a VLX application that is loaded in its own namespace
*VL-VLX-LOADED-P - Determines whether a separate-namespace VLX is currently
loaded.
Note: All definitions starting with a * were taken from the AutoLISP Programmers
Reference.
Answers to Review Questions
2. In a single document interface environment, applications and variables were confined
to the current document. Once a document was closed and a new document was opened
in its place, any applications that were previously loaded (not using ACAD.LSP) must be
reloaded before being executed.
3. Its contents can be automatically loaded by either appending the Acaddoc.lsp file or by
using the vl-vload-all (vl-load-all filename) function.
4. By using the vl-doc-export (vl-doc-export 'function) function.
5. By using the vl-doc-ref (vl-doc-ref 'symbol), vl-doc-set (vl-doc-set 'symbol value) and
vl-propagate (vl-propagate 'symbol)functions.
6. By using either the the vl-list-loaded-vls and/or vl-list-exposed-functions functions.
7. They provide the developer with a means of controlling unanticipated condition that
might cause the program to respond in a manner that could be harmful to the program,
output and/or computer.
8. To pass control from a VLX’s error-trapping function to the document’s error-trapping
function, the AutoLISP vl-exit-with-error (vl-exit-with-error msg) function can be used.
To pass an error message to the documents NameSpace, the following expressions would
be added to the VLX application’s source code:
(defun *error* (msg).
9. To provide documents and applications with a means of sharing data between
NameSpaces.
10. By using the VL-DOC-REF, VL-DOC-SET, and VL-PROPAGATE functions.
11. False, AutoLISP is limited to working with one document at a time. An AutoLISP
application cannot issue any entity creation or modification functions in a NameSpace
different from the one where the application is currently running.
Chapter Twelve
Definitions
Windows registry - is a system of proprietary binary database files whose primary
purpose is to ensure the integrity of the computer’s operating system and applications by
storing important settings and information
Initialization file - Early versions of Windows (3.X) applications stored this information
in initialization (.INI) files. Initialization files are ASCII based text files that are limited
in length to 64K. This created a problem: because these files were ASCII text files, they
were considered low security and therefore could be edited using any text editor. Anyone
using a text editor could easily alter the contents of these files; if the person editing the
file made a mistake, then the program would either not function properly or in most cases
not start at all
Subtree – The main Windows registry is comprised of six main components called
subtrees: HKEY_LOCAL_MACHINE, HKEY_CLASS_ROOT,
HKEY_CURRENT_USER, HKEY_USERS, HKEY_CURRENT_CONFIG, and
HKEY_DYN_DATA.
Subkey - Each subtree is made up of subkeys. The subkeys contained in each subtree may
also contain subkeys or they may contain active keys. It is the active keys that store the
actual values associated with a particular application
Answers to Review Questions
2. Initialization files are ASCII based text files that are limited in length to 64K. This
created a problem: because these files were ASCII text files, they were considered low
security and therefore could be edited using any text editor.
3. Information can be stored in a centrilizated location, It is secure from the average user
(meaning that information can not be accessed using Notepad, and the application is not
limited to storing only 64K at a time.
4. Registry Subtree
Subtree Name
Description
HKEY_LOCAL_MACHIN Contains information regarding the local computer’s
E
hardware and software (bus type, system memory,
device drivers, etc.).
HKEY_CLASSES_ROOT
Contains data for OLE and file class association.
HKEY_CURRENT_USER
Contains profile information for the current user
(environment variables, desktop settings, network
connections, etc.).
HKEY_USERS
Contains all actively loaded user profile information.
HKEY_CURRENT_CONF Contains hardware information used by the local
IG
computer during startup.
HKEY_DYN_DATA
Contains points to dynamic information that
constantly changes from session to session.
5. vl-registry-descendents (vl-registry-descendents reg-key [val-names]), vl-registry-read
(vl-registry-read reg-key [val-name]), and vlax-product-key (vlax-product-key).
6. vl-registry-delete (vl-registry-delete reg-key [val-name]) and vl-registry-write (vlregistry-write reg-key [val-name val-data])
7. To incorporate VBA applications into an AutoLISP program, Autodesk has provided
two functions, vl-vbaload (vl-vbaload filename) and vl-vbarun (vl-vbarun macroname),
for loading and executing VBA applications. The vl-vbaload function, when supplied
with a string representing the name and location of a Visual Basic project file, loads the
project into memory. The vl-vbarun function, when supplied with a string representing
the name of a loaded macro, executes that macro.