Jump to content
Ahankhah

Impossible Mission? Wanted Command Break

Recommended Posts

Ahankhah

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

Share this post


Link to post
Share on other sites
Lee Mac
(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)
)

Share this post


Link to post
Share on other sites
pBe

"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

Share this post


Link to post
Share on other sites
Lee Mac
:) ........

Share this post


Link to post
Share on other sites
Ahankhah
(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

Share this post


Link to post
Share on other sites
Ahankhah
"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: ;)

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
Ahankhah

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

 

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

Share this post


Link to post
Share on other sites
Ahankhah
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?:)

Share this post


Link to post
Share on other sites
Lee Mac
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)
)

Share this post


Link to post
Share on other sites
Ahankhah

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)

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
Ahankhah

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

Share this post


Link to post
Share on other sites
Lee Mac
Thank you Lee for sharing us your valuable knowledge :oops:

 

You're very welcome Mehrdad :)

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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