基于 嘉立创EDA专业版官方扩展API文档 深度分析
文档来源:https://prodocs.lceda.cn/cn/api/guide/
生成日期:2026-07-06


一、核心认知:LCEDA 扩展 API 的架构

1.1 它是什么

LCEDA专业版提供了一套前端 JS/TS 扩展 API,允许开发者在编辑器内运行自定义脚本,直接操控原理图、PCB、元件库、DRC检查等所有功能。每个扩展是一个独立的 JavaScript 脚本,运行在隔离的作用域内。

┌──────────────────────────────────────────┐
│           LCEDA Pro 编辑器              │
│                                          │
│  ┌────────┐  ┌────────┐  ┌──────────┐  │
│  │ 扩展A  │  │ 扩展B  │  │ AI扩展   │  │
│  │ (独立) │  │ (独立) │  │ (我们的) │  │
│  └───┬────┘  └───┬────┘  └────┬─────┘  │
│      │            │             │        │
│      └────────────┼─────────────┘        │
│                   ▼                      │
│         ┌─────────────────┐             │
│         │  eda 对象 (API) │             │
│         │  - SCH_PrimitiveComponent     │
│         │  - PCB_PrimitiveComponent     │
│         │  - SCH_Drc / PCB_Drc         │
│         │  - SCH_Document / PCB_Document│
│         │  - DMT_EditorControl         │
│         │  - LIB_LibrariesList         │
│         │  - SYS_IFrame               │
│         └────────┬────────┘             │
│                  ▼                      │
│         ┌─────────────────┐             │
│         │  LCEDA 核心引擎  │             │
│         └─────────────────┘             │
└──────────────────────────────────────────┘

1.2 已有的 AI 相关官方项目

从辅助项目文档中发现,LCEDA 官方已经在推进 AI 集成:

项目 类型 描述
eext-run-api-gateway EasyEDA Extension EDA ↔ AI 网关扩展
easyeda-api-skill AI Skill 扩展 API AI Skill

这说明官方已经意识到了 AI + EDA 的需求并开始布局。我们的方案是在此基础上的深化。


二、AI Agent 绘制原理图 —— 完整技术路线

2.1 核心 API 类

绘制原理图需要操作以下官方 API:

API 类 作用 关键方法
SCH_PrimitiveComponent 原理图元件操作 create() modify() delete() getAll() placeComponentWithMouse()
SCH_Document 原理图文档操作 autoLayout() autoRouting() save()
LIB_LibrariesList 库管理 getAllLibrariesList() search()
DMT_Schematic 原理图管理 createSchematic() createSchematicPage()
SCH_Net 网络管理 网络创建和连接
SCH_Drc DRC 检查 check()

2.2 绘制流程(三步法)

Step 1: AI Agent 分析需求 → 生成网表 JSON
Step 2: LCEDA 扩展读取网表 → 创建 + 放置元件
Step 3: 自动布局 + 自动布线 → 人工微调
Step 1: AI Agent 生成网表(在 LCEDA 外部完成)

AI Agent(如 Hermes + DeepSeek)分析设计需求,输出标准化网表 JSON:

// AI Agent 输出的网表格式(传递给 LCEDA 扩展)
interface AIGeneratedNetlist {
  components: Array<{
    lcsc: string;           // LCSC 元件编号,如 "C17577866"
    designator: string;     // 位号,如 "U1", "R1", "C1"
    deviceType: "resistor" | "capacitor" | "chip" | "diode" | "triode" | "oscillator" | "inductive" | "otherDevice";
    x?: number;            // 可选坐标
    y?: number;            // 可选坐标
    rotation?: number;     // 可选旋转角度
  }>;
  nets: Array<{
    name: string;           // 网络名,如 "VCC_3V3", "GND", "USB_DP"
    connections: Array<{
      designator: string;   // 元件位号
      pinNumber: string;    // 引脚编号
    }>;
  }>;
  netFlags?: Array<{
    type: "ground" | "power" | "analogGround" | "protectGround";
    netName: string;
  }>;
  netPorts?: Array<{
    type: "in" | "out" | "bi";
    netName: string;
    position: { x: number; y: number };
  }>;
}

示例:STM32H753 最小系统网表(AI Agent 输出)

{
  "components": [
    { "lcsc": "C17577866", "designator": "U1", "deviceType": "chip" },
    { "lcsc": "C131113",  "designator": "C1", "deviceType": "capacitor" },
    { "lcsc": "C131113",  "designator": "C2", "deviceType": "capacitor" },
    { "lcsc": "C14875",   "designator": "R1", "deviceType": "resistor" },
    { "lcsc": "C13740",   "designator": "Y1", "deviceType": "oscillator" }
  ],
  "nets": [
    { "name": "VCC_3V3", "connections": [
      { "designator": "U1", "pinNumber": "1" },
      { "designator": "C1", "pinNumber": "1" }
    ]},
    { "name": "GND", "connections": [
      { "designator": "U1", "pinNumber": "2" },
      { "designator": "C1", "pinNumber": "2" },
      { "designator": "C2", "pinNumber": "2" }
    ]}
  ],
  "netFlags": [
    { "type": "ground", "netName": "GND" },
    { "type": "power", "netName": "VCC_3V3" }
  ]
}
Step 2: LCEDA 扩展执行元件创建和放置

基于官方 SCH_PrimitiveComponent API:

// 扩展主入口 - 在 LCEDA 编辑器内运行
import { eda } from '@jlceda/pro-api-types';

async function placeComponentsFromAI(netlist: AIGeneratedNetlist) {
  // 1. 逐个创建原理图元件
  for (const comp of netlist.components) {
    const component = eda.sch_PrimitiveComponent.create();
    
    // 设置元件属性
    component.setSupplierId(comp.lcsc);       // LCSC 编号
    component.setDesignator(comp.designator);  // 位号
    component.setX(comp.x || 0);
    component.setY(comp.y || 0);
    component.setRotation(comp.rotation || 0);
    
    await component.done();  // 确认创建,写入设计文档
  }
  
  // 2. 创建网络标志(GND/VCC等)
  if (netlist.netFlags) {
    for (const flag of netlist.netFlags) {
      const netFlag = eda.sch_PrimitiveComponent.createNetFlag();
      const uuidFn = {
        ground: () => eda.sch_PrimitiveComponent.setNetFlagComponentUuid_Ground,
        power: () => eda.sch_PrimitiveComponent.setNetFlagComponentUuid_Power,
        analogGround: () => eda.sch_PrimitiveComponent.setNetFlagComponentUuid_AnalogGround,
        protectGround: () => eda.sch_PrimitiveComponent.setNetFlagComponentUuid_ProtectGround,
      }[flag.type];
      if (uuidFn) uuidFn();
      await netFlag.done();
    }
  }
  
  // 3. 保存
  await eda.sch_Document.save();
}
Step 3: 自动布局 + 自动布线

官方提供了 Beta 版的 autoLayout()autoRouting()

async function autoLayoutAndRoute(netlist: AIGeneratedNetlist) {
  // 获取所有已放置元件
  const allComponents = await eda.sch_PrimitiveComponent.getAll();
  const uuids = allComponents.map(c => c.getPrimitiveId());
  
  // 自动布局(传入网表和元件类型信息)
  await eda.sch_Document.autoLayout({
    uuids: uuids,
    netlist: convertToAPINetlist(netlist),
    designatorDeviceTypeMap: buildDeviceTypeMap(netlist.components)
  });
  
  // 自动布线
  await eda.sch_Document.autoRouting({
    uuids: uuids,
    netlist: convertToAPINetlist(netlist),
    designatorDeviceTypeMap: buildDeviceTypeMap(netlist.components)
  });
  
  // 保存
  await eda.sch_Document.save();
}

2.3 完整技术架构图

┌─────────────────────────────────────────────────┐
│                   AI Agent 层                    │
│                                                  │
│  ┌─────────────┐   ┌──────────────────────┐     │
│  │ Hermes Agent│   │  Claude Code /       │     │
│  │ (需求理解)  │   │  DeepSeek (代码生成) │     │
│  └──────┬──────┘   └──────────┬───────────┘     │
│         │                      │                 │
│         └──────────┬───────────┘                 │
│                    ▼                             │
│         ┌─────────────────────┐                 │
│         │  网表生成引擎       │                 │
│         │  (JSON Schema 约束) │                 │
│         └─────────┬───────────┘                 │
│                   │                             │
├───────────────────┼─────────────────────────────┤
│                   │        LCEDA 扩展层          │
│                   ▼                             │
│  ┌─────────────────────────────────────────┐   │
│  │  LCEDA Pro 扩展 (.eext)                  │   │
│  │                                          │   │
│  │  ┌─────────────────────────────────┐    │   │
│  │  │  src/index.ts (主入口)          │    │   │
│  │  │  - 读取 AI 网表 JSON            │    │   │
│  │  │  - SCH_PrimitiveComponent CRUD  │    │   │
│  │  │  - autoLayout / autoRouting     │    │   │
│  │  │  - DRC 自动检查                 │    │   │
│  │  └─────────────────────────────────┘    │   │
│  │                                          │   │
│  │  ┌─────────────────────────────────┐    │   │
│  │  │  iframe/ (可选自定义UI)         │    │   │
│  │  │  - 网表粘贴区域                 │    │   │
│  │  │  - 进度展示                     │    │   │
│  │  │  - 错误提示                     │    │   │
│  │  └─────────────────────────────────┘    │   │
│  └─────────────────────────────────────────┘   │
│                   │                             │
│                   ▼                             │
│  ┌─────────────────────────────────────────┐   │
│  │  LCEDA Pro 编辑器核心                    │   │
│  │  - eda 对象 (所有 API 入口)             │   │
│  │  - 渲染引擎                              │   │
│  │  - 设计文档存储                          │   │
│  └─────────────────────────────────────────┘   │
└─────────────────────────────────────────────────┘

三、AI Agent 检查原理图 & PCB —— DRC/ERC 自动化

3.1 官方 DRC API

LCEDA Pro 提供了完整的 DRC 检查 API:

API 类 作用 方法
SCH_Drc 原理图 DRC check(strict, userInterface, includeVerboseError)
PCB_Drc PCB DRC check(strict, userInterface, includeVerboseError)
PCB_Drc 差分对管理 createDifferentialPair() getAllDifferentialPairs()
PCB_Drc 等长网络组 createEqualLengthNetGroup() getAllEqualLengthNetGroups()
PCB_Drc 网络类 createNetClass() getAllNetClasses()
PCB_Drc 设计规则配置 saveRuleConfiguration() getCurrentRuleConfiguration()

3.2 三级检查体系

第一级:官方 DRC(机械检查)
// 直接调用官方 DRC
async function runBuiltInDRC() {
  // 原理图 DRC - 严格模式
  const schResult = await eda.sch_Drc.check(
    true,   // strict: 严格模式
    true,   // userInterface: 显示 UI
    true    // includeVerboseError: 包含详细错误
  );
  
  // PCB DRC
  const pcbResult = await eda.pcb_Drc.check(true, true, true);
  
  return { schResult, pcbResult };
}
第二级:AI Agent 语义检查(智能检查)

在官方 DRC 基础上,AI Agent 做更深层的语义分析:

interface AIDesignCheck {
  category: "bom" | "power" | "mcu_specific" | "decoupling" | "impedance";
  severity: "error" | "warning" | "info";
  message: string;
  location?: { designator: string; pin?: string };
  suggestion: string;
}

async function aiSemanticCheck(): Promise<AIDesignCheck[]> {
  const checks: AIDesignCheck[] = [];
  
  // 1. 收集当前设计状态
  const allComponents = await eda.sch_PrimitiveComponent.getAll();
  const allNets = await eda.pcb_Net.getAllNets();
  
  // 2. 构建设计上下文(发送给 AI Agent)
  const designContext = {
    components: allComponents.map(c => ({
      designator: c.getDesignator(),
      lcsc: c.getSupplierId(),
      name: c.getName(),
      pins: c.getAllPins()
    })),
    nets: allNets.map(n => ({
      name: n.name,
      connections: n.connections
    }))
  };
  
  // 3. 调用 AI Agent 分析(通过 HTTP 请求或 WebSocket)
  const aiResponse = await fetch('http://localhost:11434/api/generate', {
    method: 'POST',
    body: JSON.stringify({
      model: 'deepseek-v4-pro',
      prompt: buildCheckPrompt(designContext, checkRules),
      stream: false
    })
  });
  
  // 4. 解析 AI 输出为检查项
  const aiChecks = parseAIResponse(await aiResponse.json());
  
  return [...checks, ...aiChecks];
}

AI 检查规则模板(发送给 AI Agent 的 prompt):

你是硬件设计检查专家。请检查以下原理图:

【设计背景】
- 主控芯片:STM32H753IIK6
- 板层:6层
- 外设:USB HS, CAN FD, USART x3, DDR3L

【检查规则】
1. VCAP 引脚必须接 2.2μF 陶瓷电容到地(STM32H753 硬性要求)
2. USB_DP/USB_DM 必须为差分对,90Ω 差分阻抗
3. NRST 必须接 100nF 到地 + 10K 上拉到 VDD
4. BOOT0 下拉到 GND(Flash 启动模式)
5. 每个 VDD 引脚附近至少一个 100nF 去耦电容
6. CAN 总线终端电阻 120Ω
7. 检查是否有未连接的输入引脚(悬空)
8. 电源网络隔离检查(3.3V 和 5V 不能混接)

【设计数据】
{designContext_json}

请逐条检查,输出格式:
{ "check_item": "规则描述", "status": "pass|fail|warn", "detail": "具体问题", "suggestion": "修复建议" }
第三级:视觉指示(在编辑器内标注问题)
async function highlightAIResults(checks: AIDesignCheck[]) {
  const failedChecks = checks.filter(c => c.severity === 'error');
  
  // 使用官方 generateIndicatorMarkers 在画布上标注问题位置
  for (const check of failedChecks) {
    if (check.location) {
      const comp = await findComponentByDesignator(check.location.designator);
      if (comp) {
        const bbox = await eda.sch_Primitive.getPrimitivesBBox([comp.getPrimitiveId()]);
        
        await eda.dmt_EditorControl.generateIndicatorMarkers(
          [{
            type: 'rectangle',
            left: bbox.left,
            right: bbox.right,
            top: bbox.top,
            bottom: bbox.bottom
          }],
          { r: 255, g: 0, b: 0, alpha: 0.3 },  // 红色半透明
          2,   // 线宽
          true // 自动缩放到标记位置
        );
      }
    }
  }
}

3.3 检查清单(STM32H753 6层板示例)

基于你的 STM32H753 Wiki 知识和官方 DRC API 能力:

检查项 实现方式 优先级
VCAP 引脚接法 AI 语义检查 🔴 致命
去耦电容数量和位置 AI 语义检查 🔴 致命
电源网络隔离 AI 语义检查 🔴 致命
未连接输入引脚 官方 DRC + AI 增强 🟡 警告
USB 差分对阻抗 90Ω PCB_Drc.createDifferentialPair() 🔴 致命
DDR3L 布线等长 PCB_Drc.createEqualLengthNetGroup() 🟡 警告
CAN 终端电阻 120Ω AI 语义检查 🟡 警告
晶振负载电容 AI 语义检查 🟡 警告
BOM 完整性 AI 语义检查 🟡 警告
封装-符号匹配 官方 DRC 🔵 信息
丝印重叠 官方 DRC 🔵 信息
最小线宽/间距 官方 DRC 🔴 致命

四、开发环境搭建(最小可行步骤)

4.1 环境准备

# 1. 安装 Node.js (>= 20.5.0)
node -v  # 确认版本

# 2. 克隆官方 SDK
git clone --depth=1 https://gitee.com/jlceda/pro-api-sdk.git
cd pro-api-sdk

# 3. 安装依赖
npm install

# 4. 安装类型定义(已预配在 SDK 内)
npm install --save-dev @jlceda/pro-api-types

4.2 修改 extension.json

{
  "name": "ai-schematic-agent",
  "uuid": "",
  "displayName": "AI 原理图 Agent",
  "description": "AI驱动的原理图自动绘制与设计检查",
  "version": "1.0.0",
  "publisher": "Your Name",
  "engines": { "eda": "^2.3.0" },
  "categories": ["Schematic", "PCB"],
  "entry": "./dist/index",
  "headerMenus": {
    "sch": [{
      "id": "ai-agent",
      "title": "AI Agent",
      "menuItems": [
        { "id": "ai-draw", "title": "AI 绘制原理图", "registerFn": "drawSchematicFromAI" },
        { "id": "ai-check", "title": "AI 检查设计", "registerFn": "checkDesignWithAI" },
        { "id": "ai-drc", "title": "运行全部 DRC", "registerFn": "runAllDRC" }
      ]
    }],
    "pcb": [{
      "id": "ai-agent-pcb",
      "title": "AI Agent",
      "menuItems": [
        { "id": "ai-check-pcb", "title": "AI 检查 PCB", "registerFn": "checkPCBWithAI" },
        { "id": "ai-route", "title": "AI 辅助布线", "registerFn": "assistRouting" }
      ]
    }]
  }
}

4.3 编写主入口

// src/index.ts
import { eda, ESYS_ToastMessageType } from '@jlceda/pro-api-types';

// 导出给 extension.json 的 headerMenus 使用
export async function drawSchematicFromAI() {
  eda.sys_ToastMessage.showMessage('请粘贴 AI 生成的网表 JSON...', ESYS_ToastMessageType.INFO);
  
  // 打开自定义 UI 接收网表输入
  eda.sys_IFrame.openIFrame('/iframe/netlist-input.html', 600, 800);
}

export async function checkDesignWithAI() {
  eda.sys_ToastMessage.showMessage('AI 设计检查中...', ESYS_ToastMessageType.INFO);
  
  // 1. 运行官方 DRC
  await eda.sch_Drc.check(true, false, false);
  
  // 2. 收集设计数据发送给 AI
  const checks = await aiSemanticCheck();
  
  // 3. 展示结果
  showCheckResults(checks);
}

export async function runAllDRC() {
  await eda.sch_Drc.check(true, true, true);  // 原理图
  await eda.pcb_Drc.check(true, true, true);  // PCB
}

export async function checkPCBWithAI() {
  // PCB 专用检查
}

export async function assistRouting() {
  // AI 辅助布线
}

4.4 编译和安装

# 编译
npm run build

# 生成 .eext 文件在 ./build/dist/
# 在 LCEDA Pro 编辑器中:设置 → 扩展 → 安装本地扩展 → 选择 .eext 文件

五、Hermes Agent 与 LCEDA 的通信方案

5.1 三种集成模式

模式 A:文件桥接(最简单)
Hermes Agent  →  生成网表 JSON 文件  →  LCEDA 扩展读取文件  →  执行绘制
              ←  导出 DRC 结果 JSON  ←  LCEDA 扩展检查完成  ←

文件路径:/home/ros2/lceda-bridge/
  ├── netlist-input.json    ← Hermes Agent 写入
  ├── drc-results.json      ← LCEDA 扩展写入
  └── check-requests.json   ← 检查请求
模式 B:HTTP 桥接(实时双向)
Hermes Agent (localhost:8765)  ←──HTTP──→  LCEDA 扩展 (fetch API)

POST /api/netlist           →  上传网表,触发绘制
POST /api/check-request     →  发起设计检查
GET  /api/check-results     ←  获取检查结果
GET  /api/design-context    ←  获取当前设计状态
模式 C:WebSocket 实时协作(最强大)
Hermes Agent (WebSocket Server)  ←──WS──→  LCEDA 扩展 (WebSocket Client)

实时事件:
  - 元件放置完成通知
  - DRC 实时反馈
  - AI 逐步骤展示推理过程

5.2 推荐起步方案:模式 A + 模式 B 混合

初期用文件桥接验证流程,稳定后切 HTTP 实现实时交互。


六、分阶段实施路线图

Phase 1: 基础验证(1-2天)
├── 搭建 pro-api-sdk 开发环境
├── 编写 Hello World 扩展,验证在 LCEDA Pro 中能运行
├── 测试 SCH_PrimitiveComponent.create() 手动放置一个元件
└── 测试 SCH_Drc.check() 跑通 DRC

Phase 2: 元件库打通(2-3天)
├── 实现 LIB_LibrariesList 搜索功能
├── 通过 LCSC 编号自动查找元件
├── 批量创建元件的函数封装
└── 测试 STM32H753 + 10个外设元件自动放置

Phase 3: AI 网表生成(3-5天)
├── Hermes Agent 端:定义网表 JSON Schema
├── Hermes Agent 端:根据设计需求生成网表
├── LCEDA 扩展端:读取 JSON 文件创建元件
├── 集成 autoLayout / autoRouting
└── 联调:从需求描述到完整原理图

Phase 4: 智能检查(3-5天)
├── Hermes Agent 端:设计检查规则库
├── LCEDA 扩展端:收集设计上下文
├── 实现 HTTP 通信桥接
├── AI 语义检查 + 官方 DRC 融合
└── generateIndicatorMarkers 视觉标注

Phase 5: 完整工作流(3-5天)
├── 自定义 IFrame UI(网表粘贴/检查报告)
├── 增量更新(只改变化的部分)
├── 历史版本对比
├── 一键 BOM 导出 + 立创商城比价
└── 发布到扩展广场

七、关键 API 速查表

7.1 原理图元件操作

// 创建元件
const comp = eda.sch_PrimitiveComponent.create();
comp.setSupplierId("C17577866");     // LCSC 编号
comp.setDesignator("U1");            // 位号
comp.setX(1000);                     // X 坐标 (0.01inch)
comp.setY(2000);                     // Y 坐标
comp.setRotation(0);                 // 旋转角度
comp.setAddIntoBom(true);            // 加入 BOM
comp.setAddIntoPcb(true);            // 转换到 PCB
await comp.done();                   // 确认创建

// 查询元件
const all = await eda.sch_PrimitiveComponent.getAll();
const one = await eda.sch_PrimitiveComponent.get("primitive-id");

// 修改元件
const target = await eda.sch_PrimitiveComponent.get("primitive-id");
target.setDesignator("U2");
target.setX(2000);
await target.done();

// 删除元件
await eda.sch_PrimitiveComponent.delete("primitive-id");

7.2 PCB 元件操作

// 创建 PCB 元件
const footprint = eda.pcb_PrimitiveComponent.create();
footprint.setDesignator("U1");
footprint.setFootprint("LQFP-100");  // 封装名
await footprint.done();

// 交互式放置(跟鼠标)
await eda.pcb_PrimitiveComponent.placeComponentWithMouse("primitive-id");
await eda.pcb_PrimitiveComponent.placeFootprintWithMouse("footprint-uuid");

7.3 编辑器控制

// 打开文档
const tabId = await eda.dmt_EditorControl.openDocument("schematic-uuid");

// 缩放到所有图元
await eda.dmt_EditorControl.zoomToAllPrimitives(tabId);

// 获取画布截图(用于 AI 视觉分析)
const blob = await eda.dmt_EditorControl.getCurrentRenderedAreaImage(tabId);

// 生成视觉标记(标注问题位置)
await eda.dmt_EditorControl.generateIndicatorMarkers(
  [{ type: 'rectangle', left: 100, right: 200, top: 100, bottom: 200 }],
  { r: 255, g: 0, b: 0, alpha: 0.3 },
  2, true, tabId
);

// 移除标记
await eda.dmt_EditorControl.removeIndicatorMarkers(tabId);

7.4 文档操作

// 保存
await eda.sch_Document.save();
await eda.pcb_Document.save();

// 自动布局(传入网表)
await eda.sch_Document.autoLayout({
  uuids: [...],
  netlist: { component: {...} },
  designatorDeviceTypeMap: { "U1": "chip", "R1": "resistor" }
});

// PCB 自动布线
await eda.pcb_Document.autoRouting({
  nets: ["VCC", "GND", "SDA", "SCL"],
  ignoreNets: ["NC"],
  cornerStyle: EPCB_AutoRoutingCornerStyle.DEGREE_45,
  optimization: EPCB_AutoRoutingOptimization.COMPLETION
});

7.5 库搜索

// 搜索封装
const results = await eda.lib_Footprint.search("LQFP-100");

// 搜索元件
const components = await eda.lib_Footprint.searchByProperties({
  packageType: "LQFP",
  pinCount: 100
});

// 注册外部库
await eda.lib_LibrariesList.registerExtendLibrary("AI Library", {
  getList: async () => [...],
  search: async (keyword) => [...]
});

7.6 网络操作

// 获取所有网络
const nets = await eda.pcb_Net.getAllNets();
const netNames = await eda.pcb_Net.getAllNetsName();

// 获取指定网络的所有图元
const primitives = await eda.pcb_Net.getAllPrimitivesByNet("VCC", [...]);

// 高亮/选中网络
await eda.pcb_Net.highlightNet("VCC");
await eda.pcb_Net.selectNet("GND");

// 获取网表
const netlist = await eda.pcb_Net.getNetlist("standard");

7.7 事件监听

// 监听编辑器标签页事件
eda.dmt_Event.addEditorTabEventListener(
  "my-listener",
  "all",  // 监听所有事件类型
  (eventType, props) => {
    console.log(`文档 ${props.title} 事件: ${eventType}`);
    // eventType: 打开/关闭/切换
  }
);

// 监听图元变更事件
eda.sch_Event.addPrimitiveEventListener("my-primitive-listener", ...);
eda.pcb_Event.addPrimitiveEventListener("my-primitive-listener", ...);

八、注意事项和最佳实践

8.1 坐标系统

  • 原理图/符号:坐标单位跨度 0.01inch
  • PCB/封装:坐标单位跨度 mil
  • 使用 convertCanvasOriginToDataOrigin() 和反向方法进行坐标转换

8.2 异步操作

所有写操作(create/modify/delete)都是异步的,必须 await .done() 才能确认变更保存到设计文档。

8.3 调试技巧

# 在 LCEDA Pro URL 后加参数进入调试模式
https://pro.lceda.cn/editor?cll=debug

# 安全模式(禁用所有扩展)
https://pro.lceda.cn/editor?safetyMode=true

# 灭霸模式(清除所有扩展数据)⚠️ 危险
https://pro.lceda.cn/editor?DANGEROUS_OPERATION_DeleteExtensionStorage=true

8.4 性能考虑

  • 批量创建元件时,逐个 await .done() 避免竞态
  • 大量元件操作时考虑分批处理
  • DRC 检查可能耗时较长,用 userInterface: false 做后台检查

8.5 兼容性

  • API 接口遵循语义化版本控制(major.minor.patch)
  • 主要版本更新可能引入不兼容变更
  • Beta 标记的 API(如 autoLayout/autoRouting)行为可能改变

九、与 Hermes Agent 的深度集成建议

9.1 自定义 Hermes Tool

封装为 Hermes Agent 的 Tool,实现自然语言操控:

# Hermes Agent 自定义 Tool
class LCEDATool:
    """立创EDA专业版 AI Agent 工具集"""
    
    async def draw_schematic(self, description: str) -> dict:
        """根据自然语言描述绘制原理图"""
        # 1. AI 解析描述生成网表
        netlist = await self.ai_generate_netlist(description)
        # 2. 写入桥接文件
        self.write_bridge_file("netlist-input.json", netlist)
        # 3. 通知 LCEDA 扩展执行
        return {"status": "ok", "components": len(netlist["components"])}
    
    async def check_design(self, rules: list = None) -> dict:
        """检查当前设计"""
        # 1. 发送检查请求
        # 2. 等待 LCEDA 返回结果
        # 3. 解析为可读报告
        pass
    
    async def get_design_context(self) -> dict:
        """获取当前设计完整上下文"""
        pass

9.2 自然语言工作流

用户: "帮我画一个 STM32H753 最小系统,包括 USB、CAN、SWD 接口"

Hermes Agent:
  1. 从 STM32H753 Wiki 检索引脚定义
  2. 通过 LCSC API 查找元件编号
  3. 生成网表 JSON
  4. 写入桥接文件 (/home/ros2/lceda-bridge/netlist-input.json)
  5. 通知用户: "网表已生成,请在 LCEDA Pro 中点击 AI Agent → AI 绘制原理图"

用户在 LCEDA Pro 中点击菜单:
  6. LCEDA 扩展读取网表 JSON
  7. 逐个创建元件
  8. autoLayout + autoRouting
  9. 保存 + 缩放到全部

用户: "检查一下原理图有没有问题"

Hermes Agent:
  1. 向 LCEDA 扩展请求设计上下文
  2. 接收设计数据
  3. 运行 AI 语义检查(VCAP/去耦/阻抗等)
  4. 返回检查报告

LCEDA 扩展:
  5. 运行官方 DRC
  6. 在画布上用红色标记标出问题位置

十、总结

维度 结论
可行性 ✅ 完全可行。LCEDA Pro 官方 API 已覆盖原理图/PCB/DRC/库操作全链路
复杂度 🟡 中等。JS/TS 开发 + 网表 JSON Schema + 文件桥接
官方支持 ✅ 有官方 SDK、类型定义、扩展广场、辅助项目
AI 就绪度 ✅ 已有 eext-run-api-gatewayeasyeda-api-skill 官方项目
最佳切入 Phase 2 元件库打通 + Phase 4 智能检查(先做检查,再做生成)
关键风险 autoLayout/autoRouting 仍为 Beta(可能不稳定),需人工微调
产出形态 .eext 扩展包,可发布到官方扩展广场
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐