Command Basics
About 1 min
Command Basics
WebCAD's command system allows you to create and register custom commands.
Online Examples
| Example | Description | Link |
|---|---|---|
| Simple Command | Basic command structure example | Online Demo{target="_blank"} |
| Register Command | CommandRegistry usage | Online Demo{target="_blank"} |
| Command with Preview | Preview drawing example | Online Demo{target="_blank"} |
| State Machine Command | Multi-step command example | Online Demo{target="_blank"} |
Command Structure
A command class must have a main() method as the entry point:
// Command class must have a main() method as the entry point
export class MyCommand {
async main(): Promise<void> {
// Command logic
console.log('Command executed');
}
}Register Command
Use CommandRegistry to register a command:
import { CommandRegistry, CommandDefinition, CommandOptions } from 'vjcad';
// Create command options
const options = new CommandOptions();
options.useAutoComplete = true; // Enable auto-complete
// Register command
const cmdDef = new CommandDefinition(
'MYCMD', // Command name (uppercase)
'My command description', // Description
MyCommand, // Command class
options // Options
);
CommandRegistry.regist(cmdDef);Get and Execute Command
// Get command
const cmd = CommandRegistry.item('MYCMD');
// Execute command
await Engine.editor.executerWithOp('MYCMD');CommandOptions
| Property | Type | Description |
|---|---|---|
useAutoComplete | boolean | Enable command line auto-complete |
transparent | boolean | Transparent command (can be called within other commands) |
modal | boolean | Modal command |
CommandDefinition
| Property | Type | Description |
|---|---|---|
name | string | Command name (uppercase) |
description | string | Command description |
commandClass | Class | Command class |
options | CommandOptions | Command options |
Command Lifecycle
Command Categories
WebCAD includes various types of built-in commands:
| Type | Examples |
|---|---|
| Drawing Commands | LINE, CIRCLE, ARC, PLINE |
| Modify Commands | MOVE, COPY, ROTATE, SCALE |
| View Commands | ZOOM, PAN, REGEN |
| Edit Commands | ERASE, TRIM, EXTEND |
| Property Commands | LAYER, COLOR, LINETYPE |
Next Steps
- Command Architecture - Deep dive into command system architecture
- Input System - Get user input
- Create Command - Complete command examples
- Point Picking Guide - Detailed point picking tutorial
- Entity Selection Guide - Detailed entity selection tutorial
- Command Design Patterns - Learn different command design patterns