Abstract base class for all CAD commands.

This class provides the foundation for implementing CAD commands with:

  • Command name management (global and localized names)
  • Lifecycle event handling (command start/end)
  • Execution framework with context access
  • Event notification system

Commands are the primary way users interact with the CAD system. Each command represents a specific operation like drawing lines, selecting objects, zooming, etc.

  1. Command is triggered via trigger() method
  2. commandWillStart event is fired
  3. execute() method is called with current context
  4. commandEnded event is fired
class MyDrawCommand extends AcEdCommand {
constructor() {
super();
this.globalName = 'DRAW';
this.localName = 'Draw Line';
}

execute(context: AcApContext) {
// Implement command logic here
const view = context.view;
const document = context.doc;
// ... drawing logic
}
}

// Usage
const command = new MyDrawCommand();
command.events.commandWillStart.addEventListener(args => {
console.log('Command starting:', args.command.globalName);
});
command.trigger(context);

Hierarchy (View Summary)

Constructors

Properties

Accessors

Methods

Constructors

Properties

events: {
    commandEnded: AcCmEventManager<AcEdCommandEventArgs>;
    commandWillStart: AcCmEventManager<AcEdCommandEventArgs>;
} = ...

Events fired during command execution lifecycle

Type declaration

Accessors

Methods

  • Executes the command logic.

    This abstract method must be implemented by subclasses to define the specific behavior of the command. The method receives the current application context providing access to the view and document.

    Parameters

    Returns void

    execute(context: AcApContext) {
    const view = context.view;
    const doc = context.doc;

    // Get user input
    const point = await view.editor.getPoint();

    // Create entity in document
    const entity = new SomeEntity(point);
    doc.database.addEntity(entity);
    }
  • Triggers the command execution with proper event handling.

    This method should not be overridden by subclasses as it handles the event notification workflow. Subclasses should implement the execute() method instead.

    The execution flow:

    1. Fires commandWillStart event
    2. Calls the execute() method
    3. Fires commandEnded event

    Parameters

    • context: AcApContext

      The current application context containing view and document

    Returns void

    const command = new MyCommand();
    command.trigger(docManager.context);