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")
)
gear (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")
)
)
(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_MACHINE
|
Contains information regarding the local computer’s 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_CONFIG
|
Contains hardware information used by the local 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 (vl-registry-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.
Share with your friends: |