Ahankhah Posted October 25, 2011 Posted October 25, 2011 (edited) Hi all, who knows a way to cancell a command via reactors Here is my code of traping event of starting commands. I want to prevent AutoCAD of continuing some commands, with no success: (VLR-Command-Reactor nil (list (cons :VLR-commandWillStart 'Reactor:commandWillStart ) ) ) (defun Reactor:commandWillStart (-calling-reactor- -info- / *cmdname*) (setq *cmdname* (read (car -info-))) (cond ((member *cmdname* '(STYLE DIMSTYLE DDIM )) [color=red][b](command); it doesn't work [/b][/color] ) (T (mapcar 'princ (list *cmdname* " will start."))) ) ) Any suggestion will be greatly appreciated Edited October 26, 2011 by Ahankhah Quote
Lee Mac Posted October 25, 2011 Posted October 25, 2011 (if (null *command-reactor*) (setq *command-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . commandreactorcallback))) ) ) (defun commandreactorcallback ( reactor params / cmd wsh ) (cond ( (member (setq cmd (strcase (car params))) '("STYLE" "DIMSTYLE" "DDIM")) (if (setq wsh (vlax-create-object "WScript.Shell")) (progn (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys "{ESC}")) (vlax-release-object wsh) ) ) ) ( (princ cmd) (princ " will start.") ) ) (princ) ) Quote
pBe Posted October 25, 2011 Posted October 25, 2011 (edited) "Your mission Lee, should you decide to accept it" ....... see ahankhah's post "As always, should you or any of your code failed or crash, the Forum will disavow any knowledge of your actions" ---Mission Impossible---- Edited October 25, 2011 by pBe Quote
Ahankhah Posted October 25, 2011 Author Posted October 25, 2011 (if (null *command-reactor*) (setq *command-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . commandreactorcallback))) ) ) (defun commandreactorcallback ( reactor params / cmd wsh ) (cond ( (member (setq cmd (strcase (car params))) '("STYLE" "DIMSTYLE" "DDIM")) (if (setq wsh (vlax-create-object "WScript.Shell")) (progn (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys "{ESC}")) (vlax-release-object wsh) ) ) ) ( (princ cmd) (princ " will start.") ) ) (princ) ) Lee, I am as always surprised of your knowledge. ThanX alot Quote
Ahankhah Posted October 25, 2011 Author Posted October 25, 2011 "Your mission Lee, should you decide to accept it" ....... see ahankhah's post "As always, should you or any of your code failed or crash, the Forum will disavow any knowledge of your actions" ---Mission Impossible---- One of the Impossible Missions is sending just smileys in posts to CADTutor forum. Quote
Lee Mac Posted October 25, 2011 Posted October 25, 2011 Lee, I am as always surprised of your knowledge. ThanX alot Thanks Ahankhah You may want to consider binding the WSH object to a global variable, then releasing it at the end of the session via another reactor perhaps, as opposed to creating the object everytime those commands are called. Quote
Ahankhah Posted October 25, 2011 Author Posted October 25, 2011 Lee, good teachers always bring class level upper and upper. So my best teacher, please go on... Quote
Ahankhah Posted October 26, 2011 Author Posted October 26, 2011 Thanks Ahankhah You may want to consider binding the WSH object to a global variable, then releasing it at the end of the session via another reactor perhaps, as opposed to creating the object everytime those commands are called. Lee, Would you please explain a bit more about global variable and its relationship with reactors? Quote
Lee Mac Posted October 26, 2011 Posted October 26, 2011 Lee, Would you please explain a bit more about global variable and its relationship with reactors? I thought you may be able to work it out from my hints and pointers... Anyway, here is an example: (if (null *command-reactor*) (setq *command-reactor* (vlr-command-reactor nil '((:vlr-commandwillstart . commandreactorcallback))) ) ) (if (null *editor-reactor*) (setq *editor-reactor* (vlr-editor-reactor nil '((:vlr-beginclose . editorreactorcallback))) ) ) (defun commandreactorcallback ( reactor params ) (if (member (strcase (car params)) '("STYLE" "DIMSTYLE" "DDIM")) (if (setq *wsh* (cond (*wsh*) ((vlax-create-object "WScript.Shell")))) (vl-catch-all-apply 'vlax-invoke (list *wsh* 'sendkeys "{ESC}")) ) ) (princ) ) (defun editorreactorcallback ( reactor params ) (if (and *wsh* (eq 'VLA-OBJECT (type *wsh*)) (not (vlax-object-released-p *wsh*))) (vl-catch-all-apply 'vlax-release-object (list *wsh*)) ) (if (and *command-reactor* (eq 'VLA-OBJECT (type *command-reactor*))) (vlr-remove *command-reactor*) ) (vlr-remove reactor) (princ) ) Quote
Ahankhah Posted October 26, 2011 Author Posted October 26, 2011 I thought when closing the drawing, there was no need to release objects or remove reactors, since Visual LISP and AutoCAD did it. I appreciate you for spending your valuable time solving my and other CadTutor users' problems. (P.S. English is my third language: 1-Persian, 2-Azari, 3-English) Quote
Lee Mac Posted October 26, 2011 Posted October 26, 2011 I thought when closing the drawing, there was no need to release objects or remove reactors, since Visual LISP and AutoCAD did it. There is no need to release objects within the AutoCAD Object Model (such as the ActiveDocument etc.), as AutoCAD takes care of these; however, we have created an instance of the Windows Script Host, which needs releasing. Quote
Ahankhah Posted October 27, 2011 Author Posted October 27, 2011 Thank you Lee for sharing us your valuable knowledge Quote
Lee Mac Posted October 27, 2011 Posted October 27, 2011 Thank you Lee for sharing us your valuable knowledge You're very welcome Mehrdad Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.