Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cancel command with Visual Lisp reactor

3 REPLIES 3
Reply
Message 1 of 4
vasco_rou
1872 Views, 3 Replies

Cancel command with Visual Lisp reactor

Hello
 

It is possible to cancel a command using visual lisp reactors, if someone has a possible example. If this is not there another way I could do that. I tried to use UNDEFINE but it works only with own CAD ​​commands and not with Visual Lisp command.
 

thank you

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: vasco_rou

Example using a Command Reactor to cancel the LINE command:

 

(if (null *command-reactor*)
    (setq *command-reactor*
        (vlr-command-reactor nil '((:vlr-commandwillstart . commandreactorcallback)))
    )
)

(defun commandreactorcallback ( reactor params / wsh )
    (if (eq (strcase (car params)) "LINE")
        (if (setq wsh (vlax-create-object "WScript.Shell"))
            (progn
                (vl-catch-all-apply 'vlax-invoke (list wsh 'sendkeys "{ESC}"))
                (vlax-release-object wsh)
            )
        )
    )
    (princ)
)
(vl-load-com)

 

Or, using a more efficient callback function to keep the Windows Script Host Object global:

 

(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 (eq (strcase (car params)) "LINE")
        (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)
)
(vl-load-com)

 

These are only examples however.

Message 3 of 4
andreyperm
in reply to: Lee_Mac

Thank you Lee Mac. But what can be done if needs to abort QSAVE with commandreactor callback-function?

Message 4 of 4
john.uhden
in reply to: vasco_rou

(vla-sendcommand *doc* (chr 3))

 

where:

(vl-load-com)

(setq *doc* (vla-get-activedocument (vlax-get-acad-object)))

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost