Command Stack

AutoCAD commands are stored in groups in the command stack, which is defined by the AcEdCommandStack class. One instance of the command stack is created per AutoCAD session. This stack consists of the custom commands that you have defined. The acedRegCmds() macro gives you access to the command stack.

When you add a command, you also assign it a group name. A good policy is to use your registered developer prefix for the group name to avoid name collisions with other commands. Command names within a given group must be unique, and group names must be unique. However, multiple applications can add a command of the same name, because the group name makes the commands unambiguous.

You usually add commands one at a time with the AcEdCommandStack::addCommand() function, and you remove commands by group with the removeGroup() function. You can also use the removeCmd() function to remove commands one at a time. As part of its cleanup before exiting, your application needs to remove any commands it registered.

The signature for the addCommand() function is

Acad::ErrorStatus 
addCommand(
    const char* cmdGroupName,
    const char* cmdGlobalName,
    const char* cmdLocalName,
    Adesk::Int32 commandFlags,
    AcRxFunctionPtr functionAddr,
    AcEdUIContext *UIContext = NULL,
    int fcode=-1,
    HINSTANCE hResourceHandle = NULL,
    AcEdCommand** cmdPtrRet = NULL);
cmdGroupName

ASCII representation of the group to add the command to. If the group doesn't exist, it is created before the command is added.

cmdGlobalName

ASCII representation of the command name to add. This name represents the global or untranslated name (see "Global versus Local Command Names").

cmdLocalName

ASCII representation of the command name to add. This name represents the local or translated name.

commandFlags

Flags associated with the command. Possible values are ACRX_CMD_TRANSPARENT, ACRX_CMD_MODAL, ACRX_CMD_USEPICKSET, and ACRX_CMD_REDRAW (see "Transparent versus Modal Commands").

functionAddr

Address of the function to be executed when this command is invoked by AutoCAD.

UiContext

Input pointer to AcEdUIContext callback class.

fcode

Input integer code assigned to the command.

hResourceHandle

Input resource handle to be made current when the command is executed

cmdPtrRet

Input pointer to pointer to be filled in with address of AcEdCommand object for the command being added

Note: It is recommended to start all group and command names with a prefix to avoid possible naming conflicts with other loaded applications. The prefix you choose might be an abbreviation of your company's name or another short name that helps to uniquely identify the groups and commands registered by your applications from those registered by other applications. For example, you might add the prefix of ADSK to your version of the MOVE command resulting in the final name of ASDKMOVE.