By Adam Nagy
I have a .NET application for AutoCAD and I would like to set the command flags in it dynamically. Is this possible?
You need to get the command stack and call its functions in order to change the command flags of registered commands.
This only seems possible using ObjectARX.
You could also create a COM server ARX AddIn or a managed wrapper for this functionality that could be called to do the command stack modifications.
In .NET I have this command - as you can see CommandFlags.UsePickSet is not added to the CommandMethod attribute:
[CommandMethod("TestGroup", "TestCommand", CommandFlags.Modal)]
static public void test()
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptSelectionResult psr = ed.SelectImplied();
ed.WriteMessage("No. of selected objects = " +
ed.WriteMessage("Error in TestCommand");
I select a couple of entities on the screen and then call TestCommand, but it returns an error message for the pickfirst set is not available for it.
Then I run the command defined in my ARX module to change the command flags:
static void ArxDynamicCommandFlag_SetCommandFlags(void)
AcEdCommandStack* pCmdStack =
AcEdCommand *pCmd = pCmdStack->lookupGlobalCmd(L"TestCommand");
AcRxFunctionPtr pFunc = pCmd->functionAddr();
ACHAR localName, globalName, groupName = L"TestGroup";
errCode = pCmdStack->removeCmd(groupName, globalName);
errCode = pCmdStack->addCommand(groupName, globalName, localName,
Now, when I select a couple of entities and run TestCommand again, then it prints out the number of selected entities alright.