webcad-lib-ts SDK
WebCAD基础绘制库 - TypeScript版本
本SDK提供CAD绘图功能的核心API,支持二次开发自定义命令。
本SDK的导出按以下层级组织:
二次开发命令必须使用的核心API:
增强功能的公开API:
供有经验的开发者使用:
框架内部实现,不建议直接使用:
import { getPoint, PointInputOptions, InputStatusEnum, ssSetFirst, writeMessage, LineEnt, Point2D, Engine} from 'webcad-lib-ts';export class MyLineCommand { async main() { ssSetFirst([]); const p1Result = await getPoint(new PointInputOptions("指定第一点:")); if (p1Result.status !== InputStatusEnum.OK) return; const options = new PointInputOptions("指定第二点:"); options.useBasePoint = true; options.basePoint = p1Result.value; const p2Result = await getPoint(options); if (p2Result.status !== InputStatusEnum.OK) return; const line = new LineEnt(p1Result.value, p2Result.value); line.setDefaults(); Engine.pcanvas.addEntity(line); writeMessage("<br/>直线已创建。"); }} Copy
import { getPoint, PointInputOptions, InputStatusEnum, ssSetFirst, writeMessage, LineEnt, Point2D, Engine} from 'webcad-lib-ts';export class MyLineCommand { async main() { ssSetFirst([]); const p1Result = await getPoint(new PointInputOptions("指定第一点:")); if (p1Result.status !== InputStatusEnum.OK) return; const options = new PointInputOptions("指定第二点:"); options.useBasePoint = true; options.basePoint = p1Result.value; const p2Result = await getPoint(options); if (p2Result.status !== InputStatusEnum.OK) return; const line = new LineEnt(p1Result.value, p2Result.value); line.setDefaults(); Engine.pcanvas.addEntity(line); writeMessage("<br/>直线已创建。"); }}
import { CadEventManager, CadEvents, EntityErasingEventArgs} from 'webcad-lib-ts';// 获取事件管理器实例const events = CadEventManager.getInstance();// 监听实体删除事件(可取消)events.on(CadEvents.EntityErasing, (args: EntityErasingEventArgs) => { if (args.entity.layer === "保护图层") { args.cancel = true; // 阻止删除 console.log("保护图层上的实体不允许删除"); }});// 监听命令执行事件events.on(CadEvents.CommandStarted, (args) => { console.log(`命令 ${args.commandName} 开始执行`);});// 监听文档保存事件events.on(CadEvents.DocumentSaved, (args) => { console.log(`文档 ${args.document.name} 已保存`);});// 移除监听器const handler = (args) => { console.log(args); };events.on(CadEvents.EntityAdded, handler);events.off(CadEvents.EntityAdded, handler); Copy
import { CadEventManager, CadEvents, EntityErasingEventArgs} from 'webcad-lib-ts';// 获取事件管理器实例const events = CadEventManager.getInstance();// 监听实体删除事件(可取消)events.on(CadEvents.EntityErasing, (args: EntityErasingEventArgs) => { if (args.entity.layer === "保护图层") { args.cancel = true; // 阻止删除 console.log("保护图层上的实体不允许删除"); }});// 监听命令执行事件events.on(CadEvents.CommandStarted, (args) => { console.log(`命令 ${args.commandName} 开始执行`);});// 监听文档保存事件events.on(CadEvents.DocumentSaved, (args) => { console.log(`文档 ${args.document.name} 已保存`);});// 移除监听器const handler = (args) => { console.log(args); };events.on(CadEvents.EntityAdded, handler);events.off(CadEvents.EntityAdded, handler);
webcad-lib-ts SDK
WebCAD基础绘制库 - TypeScript版本
本SDK提供CAD绘图功能的核心API,支持二次开发自定义命令。
API层级
本SDK的导出按以下层级组织:
第一层:核心公开API (@public)
二次开发命令必须使用的核心API:
第二层:扩展公开API (@public)
增强功能的公开API:
第三层:高级API (@beta)
供有经验的开发者使用:
第四层:内部API (@internal)
框架内部实现,不建议直接使用:
Example: 创建自定义命令
Example: 使用事件系统