CANCEL COMMAND IN COMMANDWILLSTART

Hi Team,
I tried to cancel command in this way:
void MeasureReactor::commandWillStart(const ACHAR* cmdStr)
{
if (AcString(L"SELGRIPS") == cmdStr)
acedPostCommand(L"CANCELCMD");
}
it doesn't work,I found that acedPostCommand only works when the command is already running but not in such context.Do you have any way to block command before it gets executed.
Best regards,
William

//////////////////////////////////////////
Hi William, instead of trying to cancel a command that already started, it would be simpler to undefine the command so that it doesn't start in the first place. You can use the _UNDEFINE command to do that. Would that work for you?
//////////////////////////////////////////
Hi William, Owen,

Thank you for your report/updates.

@William:
We are glad to hear you have a solution.

If I may, another approach could be to call the AcApDocManagerReactor::veto method. That does the trick on my computer, but I get _all as an unrecognized command (documentLockModeChanged_selgrips_veto_AllOptionStillcalled.png):

: _selgrips => documentLockModeWillChange(00000000A2287B80,2,4,2,SELGRIPS)
=> documentLockModeChanged(00000000A2287B80,0,4,4,SELGRIPS)
=> documentLockModeChanged with SELGRIPS was called.
=> documentLockModeChangeVetoed(00000000A2287B80,SELGRIPS)
: _all

Unable to recognize command "_ALL"
I recommend Owen's solution, but I am attaching the second test code below.

Kind regards,
Eugen

/*eugenv, 25.12.2023, possible solution (2) for SRSR170196 and BricsCAD V24.1.07
Terms and conditions:
The script/sample code has been written for the specific BricsCAD product and version specified herewith. It may not work with other BricsCAD products or previous or future versions of the same BricsCAD product.
The terms and conditions of the Bricsys End-User License Agreement (EULA) apply.
*/
class MyDocReactor_SR170196 : public AcApDocManagerReactor
{
public:
virtual void documentLockModeChanged(AcApDocument* doc, AcAp::DocLockMode prevLock, AcAp::DocLockMode curLock, AcAp::DocLockMode docLock, const ACHAR* context) override
{
//eug added, based on adndevblog.typepad.com/autocad/2012/05/veto-a-particular-command-in-autocad.html
//use AcApDocManagerReactor::veto
Acad::ErrorStatus es = Acad::eOk;
//SR
if (AcString(L"SELGRIPS") == context || AcString(L"_SELGRIPS") == context || AcString(L".SELGRIPS") == context || AcString(L"._SELGRIPS") == context)
{
log(AcString().format(_T(" => documentLockModeChanged with SELGRIPS was called.\n")));
es = veto(); assert(Acad::eOk == es);//eug
}
}
virtual void documentLockModeChangeVetoed(AcApDocument* doc, const ACHAR* context) override
{
}
virtual void documentLockModeWillChange(AcApDocument* doc, AcAp::DocLockMode prevLock, AcAp::DocLockMode curLock, AcAp::DocLockMode docLock, const ACHAR* context) override
{
}
};

void cmdTest()
{
static MyDocReactor_SR170196 myDocReactor;
acDocManager->addReactor(&myDocReactor);
}

void MySandboxCommand()
{
cmdTest();
}