Veto a particular command in AutoCAD

By Virupaksha Aithal

You can Veto any command inside “DocumentCollection.DocumentLockModeChanged” event. This event is called just before AutoCAD start processing the command. Refer below code which prevents the quitting of AutoCAD.

[CommandMethod("AddVetoToQuit")]
static public void AddVetoToQuit()
{
    DocumentCollection doc = Application.DocumentManager;
    doc.DocumentLockModeChanged += 
        new DocumentLockModeChangedEventHandler(
                            doc_DocumentLockModeChanged);
 
}
 
[CommandMethod("RemoveVetoToQuit")]
static public void RemoveVetoToQuit()
{
    DocumentCollection doc = Application.DocumentManager;
    doc.DocumentLockModeChanged -= 
                new DocumentLockModeChangedEventHandler(
                               doc_DocumentLockModeChanged);
 
}
 
static void doc_DocumentLockModeChanged(object sender, 
                            DocumentLockModeChangedEventArgs e)
{
    if (string.Compare(e.GlobalCommandName, "QUIT", true) == 0)
    {
        e.Veto();
    }
}

Comments

2 responses to “Veto a particular command in AutoCAD”

  1. Matinau Avatar
    Matinau

    I know this is an old post but any chance you could provide the AutoLISP equivalent? I’ve been playing around with this (vlr-DocManager-Reactor nil ‘((:vlr-documentLockModeChanged . VetoCommand))) and getting nowhere fast.

  2. Matinau Avatar
    Matinau

    My main issue is the actual veto, escaping works for some commands but not open.
    (defun VetoCommand (sender arg / globalCommand)
    (setq globalCommand (nth 4 arg)
    document (nth 0 arg)
    )
    (if (wcmatch (strcase globalCommand) “OPEN”)
    (progn
    (princ “\nCommand intercepted”)
    (vla-SendCommand document “\e\e\e”)
    )
    )
    )

Leave a Reply to MatinauCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading