Jump to content

Recommended Posts

Posted (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 :oops:

Edited by Ahankhah
Posted
(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)
)

Posted (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----

 

:lol:

Edited by pBe
Posted
(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. :o

 

ThanX alot :D

Posted
"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----

 

:lol:

 

One of the Impossible Missions is sending just smileys in posts to CADTutor forum. :lol: ;)

Posted
Lee, I am as always surprised of your knowledge. :o

 

ThanX alot :D

 

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.

Posted

Lee, good teachers always bring class level upper and upper.

 

So my best teacher, please go on... :)

Posted
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?:)

Posted
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)
)

Posted

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)

Posted
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.

Posted

Thank you Lee for sharing us your valuable knowledge :oops:

Posted
Thank you Lee for sharing us your valuable knowledge :oops:

 

You're very welcome Mehrdad :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...