The class to create, define, and register command objects.

It is used to manages all command registration and lookup functionality. Commands are organized into groups, with system commands (ACAD) and user commands (USER) being the default groups.

const commandStack = AcApDocManager.instance.commandManager;
commandStack.addCommand('USER', 'MYCOMMAND', 'MYCOMMAND', myCommandInstance);
const command = commandStack.lookupGlobalCmd('MYCOMMAND');

Constructors

Properties

DEFAUT_COMMAND_GROUP_NAME: string = 'USER'

The name of the default user command group

SYSTEMT_COMMAND_GROUP_NAME: string = 'ACAD'

The name of the system command group

Methods

  • Adds a command to the specified command group.

    Parameters

    • cmdGroupName: string

      The name of the command group. If empty, uses the default group.

    • cmdGlobalName: string

      The global (untranslated) name of the command. Must be unique within the group.

    • cmdLocalName: string

      The local (translated) name of the command. Defaults to global name if empty.

    • cmd: AcEdCommand

      The command object to add to the stack.

    Returns void

    When the global name is empty or when a command with the same name already exists

    commandStack.addCommand('USER', 'LINE', 'ligne', new LineCommand());
    
  • Return an iterator that can be used to traverse all of command objects in this command stack (that is, the iterator iterates through all commands in all groups).

    Returns AcEdCommandIterator

    Return an iterator that can be used to traverse all of command objects in this command stack.

  • Search through all of the global and untranslated names in all of the command groups in the command stack starting at the top of the stack trying to find a match with cmdName. If a match is found, the matched AcEdCommand object is returned. Otherwise undefined is returned to indicate that the command could not be found. If more than one command of the same name is present in the command stack (that is, in separate command groups), then the first one found is used.

    If a mode is specified, the command is only returned if it is compatible with that mode. Higher value modes are compatible with lower value modes.

    Parameters

    • cmdName: string

      Input the command name to search for

    • Optionalmode: AcEdOpenMode

      Optional access mode to check compatibility. Only returns the command if it's compatible with this mode.

    Returns undefined | AcEdCommand

    Return the matched AcEdCommand object if a match is found and compatible with the mode. Otherwise, return undefined.

  • Search through all of the local and translated names in all of the command groups in the command stack starting at the top of the stack trying to find a match with cmdName. If a match is found, the matched AcEdCommand object is returned. Otherwise undefined is returned to indicate that the command could not be found. If more than one command of the same name is present in the command stack (that is, in separate command groups), then the first one found is used.

    If a mode is specified, the command is only returned if it is compatible with that mode. Higher value modes are compatible with lower value modes.

    Parameters

    • cmdName: string

      Input the command name to search for

    • Optionalmode: AcEdOpenMode

      Optional access mode to check compatibility. Only returns the command if it's compatible with this mode.

    Returns undefined | AcEdCommand

    Return the matched AcEdCommand object if a match is found and compatible with the mode. Otherwise, return undefined.

  • Remove the command with the global and untranslated name cmdGlobalName from the cmdGroupName command group. Return true if successful. Return false if no command with the global and untranslated name cmdGlobalName is found in the cmdGroupName command group.

    Parameters

    • cmdGroupName: string

      Input the name of the command group containing the command to be removed

    • cmdGlobalName: string

      Input the command name which is to be removed from cmdGroupName

    Returns boolean

    Return true if successful. Return false if no command with the global and untranslated name cmdGlobalName is found in the cmdGroupName command group.

  • Remove the command group with the name GroupName from the command stack and delete the command group dictionary object and all the AcEdCommand objects stored within it.

    Parameters

    • groupName: string

      Input the name of the command group to be removed from the command stack.

    Returns boolean

    Return true if successful. Return false if no command group is found with the name GroupName.

  • Fuzzy search for commands by prefix using the command iterator.

    This method iterates through all commands in all command groups and returns those whose global or local names start with the provided prefix. The search is case-insensitive. If a mode is specified, only commands compatible with that mode are returned. Higher value modes are compatible with lower value modes.

    Parameters

    • prefix: string

      The prefix string to search for. Case-insensitive.

    • Optionalmode: AcEdOpenMode

      Optional access mode to filter commands. Only commands compatible with this mode are returned.

    Returns AcEdCommandIteratorItem[]

    An array of objects containing matched commands and their corresponding group names.

    const matches = commandStack.searchCommandsByPrefix('LI', AcEdOpenMode.Write);
    matches.forEach(item => {
    console.log(item.groupName, item.command.globalName);
    });