Input System
About 2 min
Input System
WebCAD provides a rich set of input APIs for obtaining user input such as points, selection sets, strings, and more.
PointInputOptions
Get point input:
import {
getPoint,
PointInputOptions,
InputStatusEnum,
Point2D
} from 'vjcad';
const options = new PointInputOptions("Specify point [Undo(U)/Close(C)]:");
options.keywords = ["U", "C"]; // Keywords
options.useBasePoint = true; // Enable base point
options.basePoint = new Point2D(0, 0); // Base point position for rubber-band line
options.allowNone = false; // Do not allow empty input
const result = await getPoint(options);
switch (result.status) {
case InputStatusEnum.OK:
console.log('User point:', result.value);
break;
case InputStatusEnum.Keyword:
console.log('User keyword:', result.stringResult);
break;
case InputStatusEnum.Cancel:
console.log('User canceled');
break;
case InputStatusEnum.EnterOrSpace:
console.log('User pressed Enter or Space');
break;
}PointInputOptions Properties
| Property | Type | Description |
|---|---|---|
message | string | Prompt message |
keywords | string[] | Keyword list |
useBasePoint | boolean | Whether to enable base point |
basePoint | Point2D | Base point position |
allowNone | boolean | Whether empty input is allowed |
onMouseMove | function | Mouse-move callback |
SelectionInputOptions
Get a selection set:
import {
Engine,
SelectionInputOptions,
InputStatusEnum
} from 'vjcad';
const options = new SelectionInputOptions();
options.message = "Select objects:";
options.allowMultiple = true;
options.filterTypes = ['LINE', 'CIRCLE']; // Only allow lines and circles
const result = await Engine.getSelections(options);
if (result.status === InputStatusEnum.OK) {
for (const entity of result.value) {
console.log(`Selected ${entity.type}, ID: ${entity.id}`);
}
}SelectionInputOptions Properties
| Property | Type | Description |
|---|---|---|
message | string | Prompt message |
allowMultiple | boolean | Allow multiple selection |
filterTypes | string[] | Allowed entity types |
useExisting | boolean | Use existing selection set |
StringInputOptions
Get string input:
import { Engine, StringInputOptions, InputStatusEnum } from 'vjcad';
// String input
const strOpt = new StringInputOptions("Enter text:");
const strResult = await Engine.getString(strOpt);
if (strResult.status === InputStatusEnum.OK) {
console.log('Input:', strResult.value);
}IntegerInputOptions
Get integer input:
import { Engine, IntegerInputOptions, InputStatusEnum } from 'vjcad';
// Integer input
const intOpt = new IntegerInputOptions("Enter quantity:");
intOpt.defaultValue = 10;
const intResult = await Engine.getInteger(intOpt);
if (intResult.status === InputStatusEnum.OK) {
console.log('Quantity:', intResult.value);
}RealInputOptions
Get real-number input:
import { Engine, RealInputOptions, InputStatusEnum } from 'vjcad';
// Real input
const realOpt = new RealInputOptions("Enter radius:");
realOpt.defaultValue = 50.0;
const realResult = await Engine.getReal(realOpt);
if (realResult.status === InputStatusEnum.OK) {
console.log('Radius:', realResult.value);
}KeywordInputOptions
Get keyword input:
import { Engine, KeywordInputOptions, InputStatusEnum } from 'vjcad';
// Keyword selection
const kwOpt = new KeywordInputOptions("Select mode [Rectangle(R)/Circle(C)]:");
kwOpt.keywords = ["R", "C"];
kwOpt.defaultKeyword = "R";
const kwResult = await Engine.getKeyword(kwOpt);
if (kwResult.status === InputStatusEnum.OK) {
console.log('Selected:', kwResult.value);
}InputStatusEnum
Input result status:
| Value | Description |
|---|---|
OK | Input acquired successfully |
Cancel | User canceled with ESC |
Keyword | User entered a keyword |
EnterOrSpace | User pressed Enter or Space |
Error | An error occurred |
Handling Input Results
const result = await Engine.getPoint(options);
// Handle different result statuses
if (result.status === InputStatusEnum.OK) {
// Successfully got a point
const point = result.value;
doSomething(point);
} else if (result.status === InputStatusEnum.Keyword) {
// User selected a keyword
const keyword = result.stringResult;
handleKeyword(keyword);
} else if (result.status === InputStatusEnum.Cancel) {
// User canceled
return;
} else if (result.status === InputStatusEnum.EnterOrSpace) {
// User pressed Enter, maybe use default
useDefault();
}Next Steps
- Point Input Guide - detailed tutorials and examples for point picking
- Entity Selection Guide - detailed entity-selection tutorials
- Create Command - complete command example
- Undo / Redo Mechanism - learn undo support
- Preview Drawing - learn entity preview
- API Reference - full API reference