Event Types
About 4 min
Event Types
WebCAD provides a rich event system for listening to and responding to many kinds of operations.
Online Examples
| Example | Description | Link |
|---|---|---|
| Entity Added Event | Listen to EntityAdded | Online Demo{target="_blank"} |
| Entity Modified Event | Listen to EntityModified | Online Demo{target="_blank"} |
| Selection Changed Event | Listen to SelectionChanged | Online Demo{target="_blank"} |
| Command Events | CommandStarted and CommandEnded | Online Demo{target="_blank"} |
| Document Events | DocumentOpened and DocumentSaved | Online Demo{target="_blank"} |
| Polyline Points & Event Timing | EntityAdded/EntityModified/CommandEnded differences during PLINE drawing | Online Demo{target="_blank"} |
CadEvents Enum
enum CadEvents {
// ===== Document Events =====
DocumentCreating = 'DocumentCreating', // Before create, cancelable
DocumentCreated = 'DocumentCreated', // After create
DocumentOpening = 'DocumentOpening', // Before open, cancelable
DocumentOpened = 'DocumentOpened', // After open
DocumentClosing = 'DocumentClosing', // Before close, cancelable
DocumentClosed = 'DocumentClosed', // After close
DocumentSaving = 'DocumentSaving', // Before save, cancelable
DocumentSaved = 'DocumentSaved', // After save
DocumentModified = 'DocumentModified', // After modification
DocumentSwitched = 'DocumentSwitched', // After switching document
// ===== Entity Events =====
EntityAdding = 'EntityAdding', // Before add, cancelable
EntityAdded = 'EntityAdded', // After add
EntitiesAdding = 'EntitiesAdding', // Before batch add
EntitiesAdded = 'EntitiesAdded', // After batch add
EntityModified = 'EntityModified', // After modify
EntityErasing = 'EntityErasing', // Before erase, cancelable
EntityErased = 'EntityErased', // After erase
EntitiesErasing = 'EntitiesErasing', // Before batch erase
EntitiesErased = 'EntitiesErased', // After batch erase
// ===== Command Events =====
CommandStarting = 'CommandStarting', // Before start, cancelable
CommandStarted = 'CommandStarted', // After start
CommandEnded = 'CommandEnded', // After end
CommandCancelled = 'CommandCancelled', // After cancel
// ===== Layer Events =====
LayerAdding = 'LayerAdding', // Before add, cancelable
LayerAdded = 'LayerAdded', // After add
LayerDeleting = 'LayerDeleting', // Before delete, cancelable
LayerDeleted = 'LayerDeleted', // After delete
LayerModified = 'LayerModified', // After modify
CurrentLayerChanged = 'CurrentLayerChanged', // Current layer changed
// ===== Selection Events =====
SelectionChanged = 'SelectionChanged', // Selection changed
SelectionCleared = 'SelectionCleared', // Selection cleared
// ===== View Events =====
ViewZoomed = 'ViewZoomed', // After zoom
ViewPanned = 'ViewPanned', // After pan
ViewRegenerated = 'ViewRegenerated', // After redraw
// ===== Block Events =====
BlockAdding = 'BlockAdding', // Before add, cancelable
BlockAdded = 'BlockAdded', // After add
BlockDeleting = 'BlockDeleting', // Before delete, cancelable
BlockDeleted = 'BlockDeleted', // After delete
BlockModified = 'BlockModified', // After modify
// ===== Collaboration and Version Control Events =====
// Server sync events
DocumentUploading = 'DocumentUploading', // Before upload, cancelable
DocumentUploaded = 'DocumentUploaded', // After upload
DocumentDownloading = 'DocumentDownloading', // Before download, cancelable
DocumentDownloaded = 'DocumentDownloaded', // After download
DocumentSyncStatusChanged = 'DocumentSyncStatusChanged', // Sync status changed
// Local storage events
DocumentCaching = 'DocumentCaching', // Before cache save, cancelable
DocumentCached = 'DocumentCached', // After cache save
DocumentRestoring = 'DocumentRestoring', // Before restore from cache, cancelable
DocumentRestored = 'DocumentRestored', // After restore from cache
DocumentCacheCleared = 'DocumentCacheCleared', // After cache cleared
// Branch events
BranchCreating = 'BranchCreating', // Before branch creation, cancelable
BranchCreated = 'BranchCreated', // After branch creation
BranchSwitching = 'BranchSwitching', // Before branch switch, cancelable
BranchSwitched = 'BranchSwitched', // After branch switch
BranchMerging = 'BranchMerging', // Before branch merge, cancelable
BranchMerged = 'BranchMerged', // After branch merge
BranchDeleting = 'BranchDeleting', // Before branch deletion, cancelable
BranchDeleted = 'BranchDeleted', // After branch deletion
// Patch events
PatchCreating = 'PatchCreating', // Before patch creation, cancelable
PatchCreated = 'PatchCreated', // After patch creation
PatchApplying = 'PatchApplying', // Before patch apply, cancelable
PatchApplied = 'PatchApplied', // After patch apply
PatchReverting = 'PatchReverting', // Before patch revert, cancelable
PatchReverted = 'PatchReverted', // After patch revert
// Conflict events
ConflictDetected = 'ConflictDetected', // Conflict detected
ConflictResolving = 'ConflictResolving', // Before conflict resolution, cancelable
ConflictResolved = 'ConflictResolved', // After conflict resolution
ConflictSkipped = 'ConflictSkipped', // Conflict skipped
// ===== Plugin Events =====
PluginLoading = 'PluginLoading', // Plugin begins loading
PluginLoaded = 'PluginLoaded', // Plugin finished loading
PluginActivating = 'PluginActivating', // Plugin begins activation
PluginActivated = 'PluginActivated', // Plugin activation finished
PluginDeactivating = 'PluginDeactivating', // Plugin begins deactivation
PluginDeactivated = 'PluginDeactivated', // Plugin deactivation finished
PluginUnloading = 'PluginUnloading', // Plugin begins unloading
PluginUnloaded = 'PluginUnloaded', // Plugin unloading finished
PluginError = 'PluginError', // Plugin error occurred
// ===== Context Menu Events =====
ContextMenuOpening = 'ContextMenuOpening', // Before context menu opens, cancelable and customizable
ContextMenuOpened = 'ContextMenuOpened', // After context menu opens
ContextMenuItemClicked = 'ContextMenuItemClicked', // Menu item clicked
// ===== UI Events =====
RibbonConfigChanged = 'RibbonConfigChanged' // Ribbon config changed
}Event Categories
Document Events
| Event | Description | Cancelable |
|---|---|---|
DocumentCreating | Before creating a document | Yes |
DocumentCreated | After creating a document | No |
DocumentOpening | Before opening a document | Yes |
DocumentOpened | After opening a document | No |
DocumentClosing | Before closing a document | Yes |
DocumentClosed | After closing a document | No |
DocumentSaving | Before saving a document | Yes |
DocumentSaved | After saving a document | No |
DocumentModified | After document modification | No |
DocumentSwitched | After switching the current document | No |
Entity Events
| Event | Description | Cancelable |
|---|---|---|
EntityAdding | Before adding an entity | Yes |
EntityAdded | After adding an entity | No |
EntitiesAdding | Before batch adding entities | Yes |
EntitiesAdded | After batch adding entities | No |
EntityModified | After modifying an entity | No |
EntityErasing | Before deleting an entity | Yes |
EntityErased | After deleting an entity | No |
EntitiesErasing | Before batch deleting entities | Yes |
EntitiesErased | After batch deleting entities | No |
Command Events
| Event | Description | Cancelable |
|---|---|---|
CommandStarting | Before a command starts | Yes |
CommandStarted | After a command starts | No |
CommandEnded | After a command ends | No |
CommandCancelled | After a command is canceled | No |
Layer Events
| Event | Description | Cancelable |
|---|---|---|
LayerAdding | Before adding a layer | Yes |
LayerAdded | After adding a layer | No |
LayerDeleting | Before deleting a layer | Yes |
LayerDeleted | After deleting a layer | No |
LayerModified | After modifying layer properties | No |
CurrentLayerChanged | After current layer changes | No |
Selection Events
| Event | Description |
|---|---|
SelectionChanged | After selection changes |
SelectionCleared | After selection is cleared |
SelectionChangedEventArgs
| Property | Type | Description |
|---|---|---|
document | CadDocument | Owning document |
previousSelection | EntityBase[] | Previous selection set |
currentSelection | EntityBase[] | Current selection set |
selections | EntityBase[] | Alias of currentSelection |
added | EntityBase[] | Newly added entities |
removed | EntityBase[] | Removed entities |
View Events
| Event | Description |
|---|---|
ViewZoomed | After view zoom |
ViewPanned | After view pan |
ViewRegenerated | After view redraw |
Block Events
| Event | Description | Cancelable |
|---|---|---|
BlockAdding | Before adding a block definition | Yes |
BlockAdded | After adding a block definition | No |
BlockDeleting | Before deleting a block definition | Yes |
BlockDeleted | After deleting a block definition | No |
BlockModified | After modifying a block definition | No |
Collaboration and Version Control Events
These events are used for collaboration, cloud synchronization, and version-management scenarios.
Server Sync Events
| Event | Description | Cancelable |
|---|---|---|
DocumentUploading | Before uploading a document to the server | Yes |
DocumentUploaded | After uploading a document to the server | No |
DocumentDownloading | Before downloading a document from the server | Yes |
DocumentDownloaded | After downloading a document from the server | No |
DocumentSyncStatusChanged | Document synchronization status changed | No |
Local Storage Events
| Event | Description | Cancelable |
|---|---|---|
DocumentCaching | Before saving to local cache | Yes |
DocumentCached | After saving to local cache | No |
DocumentRestoring | Before restoring from local cache | Yes |
DocumentRestored | After restoring from local cache | No |
DocumentCacheCleared | After local cache is cleared | No |
Branch Events
| Event | Description | Cancelable |
|---|---|---|
BranchCreating | Before creating a branch | Yes |
BranchCreated | After creating a branch | No |
BranchSwitching | Before switching branches | Yes |
BranchSwitched | After switching branches | No |
BranchMerging | Before merging a branch | Yes |
BranchMerged | After merging a branch | No |
BranchDeleting | Before deleting a branch | Yes |
BranchDeleted | After deleting a branch | No |
Patch Events
| Event | Description | Cancelable |
|---|---|---|
PatchCreating | Before creating a patch | Yes |
PatchCreated | After creating a patch | No |
PatchApplying | Before applying a patch | Yes |
PatchApplied | After applying a patch | No |
PatchReverting | Before reverting a patch | Yes |
PatchReverted | After reverting a patch | No |
Conflict Events
| Event | Description | Cancelable |
|---|---|---|
ConflictDetected | Conflict detected | No |
ConflictResolving | Before resolving a conflict | Yes |
ConflictResolved | After resolving a conflict | No |
ConflictSkipped | Conflict skipped | No |
Plugin Events
| Event | Description |
|---|---|
PluginLoading | Plugin starts loading |
PluginLoaded | Plugin finished loading |
PluginActivating | Plugin starts activating |
PluginActivated | Plugin activation finished |
PluginDeactivating | Plugin starts deactivating |
PluginDeactivated | Plugin deactivation finished |
PluginUnloading | Plugin starts unloading |
PluginUnloaded | Plugin unloading finished |
PluginError | Plugin error occurred |
Context Menu Events
| Event | Description | Cancelable |
|---|---|---|
ContextMenuOpening | Before the context menu opens; menu items can be customized | Yes |
ContextMenuOpened | After the context menu opens | No |
ContextMenuItemClicked | Menu item was clicked | No |
For detailed usage, see Context Menu.
UI Events
| Event | Description |
|---|---|
RibbonConfigChanged | Ribbon configuration changed; notifies RibbonBar to rerender |
Event Naming Convention
WebCAD events follow these naming rules:
- Before events ending with
-ing: fired before an operation, usually cancelable - After events ending with
-ed: fired after an operation completes and are not cancelable - Changed events: fired after a state change
// Before event example - operation can be canceled
eventManager.on(CadEvents.DocumentSaving, (args) => {
if (!validateDocument()) {
args.cancel = true; // Cancel save
Engine.writeMessage('Document validation failed. Save canceled.');
}
});
// After event example - for notification or follow-up logic
eventManager.on(CadEvents.DocumentSaved, (args) => {
console.log('Document saved:', args.document.name);
});Next Steps
- Event Usage - listen to and handle events