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();
}
}

Leave a Reply to MatinauCancel reply