PDA

View Full Version : Reactor causing "invalid AutoCAD command: nil"



bowlingbrad
2012-01-18, 05:19 PM
Auginauts,
I've scavenged some code regarding a close reactor and I don't know what is causing the "invalid AutoCAD command: nil" message. It occurs at the beginning of EVERY command I type in. I just want this reactor to recognize CLOSE, SAVE, QSAVE, QUIT.

Thanks!


(vl-load-com)
(defun smart-command-reactor (commands StartCallback EndCallback / ended)
(vl-load-reactors)
(setq ended
(vlr-command-reactor nil
'(
(:vlr-commandEnded . internal-commandEnded)
(:vlr-commandCancelled . internal-commandEnded)
(:vlr-commandFailed . internal-commandEnded)
)
)
)
(vlr-remove ended)
(vlr-command-reactor
(list
ended
StartCallback
EndCallback
(if (listp commands)
(mapcar 'strcase commands)
(list (strcase commands))
)
)
'((:vlr-commandWillStart . internal-commandWillStart))
)
)
(defun internal-commandWillStart (reactor args / data result)
(setq data (vlr-data reactor))
(if
(and
(member (car args) (last data))
(setq result (apply (cadr data) (list (car args))))
)
(progn
(vlr-data-set
(car data)
(list (caddr data) result)
)
(vlr-add (car data))
)
)
)
(defun internal-commandEnded (reactor args / data)
(setq data (vlr-data reactor))
(vlr-remove reactor)
(apply
(car data)
(list
reactor
(vlr-current-reaction-name)
(car args)
(cadr data)
)
)
)

(if *my-smart-close-reactor* (vlr-remove *my-smart-close-reactor*))

(setq *my-smart-close-reactor*
;;;;;;;;;;;;;;;;;;;;;;; I'm assuming something has to be put below here to catch the nil
(smart-command-reactor
'("CLOSE" "SAVE" "QSAVE" "QUIT")
(function
(lambda (cmdname)
(if (not gp-project-stds)
(alert "GP Project Standards cannot be found for this file!\nPlease contact your Administrator")
(gp-project-stds)
);end if
)
)

(function
(lambda (data)
(if (= nil data)
(progn
(princ "Done.")
(setvars data)
(sssetfirst nil)
(setq app nil adoc nil)
);end progn
);end if
)
)
)
)

(defun setvars (data)
(mapcar
(function
(lambda (v / r)
(setq r (getvar (car v)))
(setvar (car v) (cdr v))
(cons (car v) r)
)
)
data
)
)

ccowgill
2012-01-19, 01:47 PM
can you use an alert with a reactor?

Part of what I use:


(if (not Command_Ending_Reactor)
(setq Command_Ending_Reactor
(vlr-command-reactor
nil
'((:vlr-commandended
.
callback:commandended
)
)
) ;_ end of vlr-command-reactor
) ;_ end of setq
() ;_ the reactor is already loaded
) ;_ end of if

(if (not Command_Failed_Reactor)
(setq Command_Failed_Reactor
(vlr-command-reactor
nil
'((:vlr-commandfailed
.
callback:commandended
)
)
) ;_ end of vlr-command-reactor
) ;_ end of setq
() ;_ the reactor is already loaded
) ;_ end of if

(defun Callback:CommandEnded (Rea Cmd / tess)
;;(prompt (car Cmd)) ;; <-- Remove this line, it shows all incomming command
(if (not (member (car Cmd)
(list "OPEN" "CLOSE" "QSAVE" "SAVE" "QUIT" "UNDO" "NEW" "QNEW" "ADCENTER" "PROPERTIES" "TOOLPALETTES" "EXTERNALREFERENCES" "EGPTEMBEDMENUS" "PLOT" "PUBLISH" "_RIBBON" "VLIDE"
"ERASE" "TABLEDIT") ;_ end of list
) ;_ end of member
) ;_ end of not
(capslockoff)
) ;_ end of if

bowlingbrad
2012-01-19, 01:52 PM
Thanks Christopher.
I think I'm going to try using your idea of a command list with (if (member...blah blah.

Maybe that will do the trick.

BlackBox
2012-01-19, 02:34 PM
FWIW - vl-position is (slightly?) faster than member.

hfrancis
2013-03-14, 02:41 PM
I am confused.
Where do Rea and Cmd get their values from in Callback:CommandEnded?
I first found your method where you described (Defun Command_ended_Command (In_ReactorName In_Command / ) ...)
I've been trying to get that reactor scheme to work for me after I insert a block but so far no dice.
I expect the function call to provide these but I can't see how it does in your reactor code.
Is issuing these vars with the function call just what a reactor always does?

BlackBox
2013-03-14, 03:00 PM
Wow this is an old thread. LoL


I am confused.
Where do Rea and Cmd get their values from in Callback:CommandEnded?
I first found your method where you described (Defun Command_ended_Command (In_ReactorName In_Command / ) ...)
I've been trying to get that reactor scheme to work for me after I insert a block but so far no dice.
I expect the function call to provide these but I can't see how it does in your reactor code.
Is issuing these vars with the function call just what a reactor always does?

No worries; we all start somewhere, and Reactors are a notorious challenge, but once overcome can be quite useful.

When you create the Reactor, you specify the Callback... When the Reactor fires, it (the Reactor) supplies the arguments for the Callback as noted in the developer documentation on vlr-Command-Reactor (http://exchange.autodesk.com/autocad/enu/online-help/browse#WS1a9193826455f5ff1a32d8d10ebc6b7ccc-67c9.htm):




Arguments

data

Any AutoLISP data to be associated with the reactor object; otherwise nil if no data is to be associated with the reactor.

callbacks

A list of pairs of the following form:
(event-name . callback_function)
where event-name is one of the symbols listed in the “Command reactor events” table below, and callback_function is a symbol representing a function to be called when the event fires. Each callback function accepts two arguments:
reactor_object The VLR object that called the callback function.
list A list containing a single element, the string identifying the command.

Return Values

The reactor_object argument.