### Example: read start X from a primitive line Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitiveline.getstate_startx.html JavaScript example that creates a test line, reads its start X using getState_StartX(), and then deletes the test object to avoid leaving test artifacts. ```javascript // 1. 创建一条测试直线,起点 (1000, 1000) const line = await eda.pcb_PrimitiveLine.create('', 1, 1000, 1000, 1600, 1000, 10); // 2. 读取起点 X const startX = line.getState_StartX(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.pcb_PrimitiveLine.delete([line.getState_PrimitiveId()]); console.log('startX:', startX); ``` -------------------------------- ### setState_StartX usage example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitiveline.setstate_startx.html Example in JavaScript that creates a test line, reads its current start X, switches to asynchronous mode, moves the start X by 300 mil, and confirms the change by refetching. ```javascript // 1. 生成本次运行专用的坐标,避免与之前保留的测试走线重合 const x = 6000 + (Math.floor(Math.random() * 100000)); const y = 2000 + (Math.floor(Math.random() * 100000)); // 2. 创建一条测试直线,起点 (x, y) const line = await eda.pcb_PrimitiveLine.create('', 1, x, y, x + 600, y, 10); // 3. 读取修改前的起点 X const before = line.getState_StartX(); // 4. 切换异步模式并平移起点 X(右移 300mil) const asyncLine = line.toAsync(); asyncLine.setState_StartX(x + 300); await asyncLine.done(); // 5. 从画布重新读取,确认修改已生效(保留现场供观察) const refetched = await eda.pcb_PrimitiveLine.get(line.getState_PrimitiveId()); const after = refetched.getState_StartX(); console.log('startX:', before, '→', after); ``` -------------------------------- ### Pin mapping example for vector port Source: https://prodocs.lceda.cn/cn/simulation/new-simulation-device Example pin mapping for a model with a vector input port (IN_VE) and a scalar output port (OUT). The vector port pins must be contiguous and use the _VE suffix. ```text 1=IN_VE, 2=IN_VE, 3=IN_VE, 4=OUT ``` -------------------------------- ### Create a project example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.dmt_project.createproject.html Demonstrates creating a project with a timestamped friendly name and verifying its creation by fetching project information. ```javascript // 1. 创建测试工程(友好名带时间戳避免重名,名称与团队留空走默认) const projectUuid = await eda.dmt_Project.createProject( `嘉立创示例_工程 ${Date.now()}`, undefined, undefined, undefined, '嘉立创示例:工程创建演示', ); // 2. 等待工作区同步后回读,确认工程已落地 await new Promise(r => setTimeout(r, 1500)); const brief = await eda.dmt_Project.getProjectInfo(projectUuid); const folderLabel = !brief?.folderUuid ? '(根目录)' : brief.folderUuid; console.log('projectUuid:', projectUuid); console.log('friendlyName:', brief?.friendlyName); console.log('folderUuid:', folderLabel); ``` -------------------------------- ### Get starting Y-coordinate of a line Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitiveline.getstate_starty.html Example demonstrating how to create a line, retrieve its starting Y-coordinate using getState_StartY, and then delete the line. ```javascript // 1. 创建一条测试直线,起点 (1000, 1000) const line = await eda.pcb_PrimitiveLine.create('', 1, 1000, 1000, 1600, 1000, 10); // 2. 读取起点 Y const startY = line.getState_StartY(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.pcb_PrimitiveLine.delete([line.getState_PrimitiveId()]); console.log('startY:', startY); ``` -------------------------------- ### JavaScript example creating a device and logging its properties Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sch_primitivecomponent.create.html Shows how to create a device component: searches a device from the system library using eda.lib_Device.search, places it at random coordinates in 10mil units to avoid overlap, passes the search result to create(), and logs resulting primitive ID, designator, position, and the BOM flag. The example uses optional parameters as specified in the method signature. ```JavaScript // 1. 从系统库搜索器件,随机坐标避免与画布已有器件重合(SCH 坐标单位 10mil) const devices = await eda.lib_Device.search(''); const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); // 2. 创建器件:搜索结果直接作为关联库器件传入,加入 BOM 并转到 PCB const comp = await eda.sch_PrimitiveComponent.create( devices[0], // 关联库器件 x, // 坐标 X y, // 坐标 Y undefined, // 子部件名称(多子部件器件才需要指定) 0, // 旋转角度 false, // 是否镜像 true, // 是否加入 BOM true // 是否转到 PCB ); // 3. 创建类保留现场,供在画布上观察摆放结果 console.log('primitiveId:', comp.getState_PrimitiveId()); console.log('designator:', comp.getState_Designator()); console.log('position:', comp.getState_X(), ',', comp.getState_Y()); console.log('addIntoBom:', comp.getState_AddIntoBom()); ``` -------------------------------- ### Example: create arc, get start X, and clean up Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivearc.getstate_startx.html Creates a test arc, reads its start X coordinate via getState_StartX(), then deletes the arc to avoid leaving test objects. Logs the retrieved startX value. ```javascript // 1. 创建一段测试圆弧,起点 (400, 300)(SCH 坐标单位 10mil) const arc = await eda.sch_PrimitiveArc.create(400, 300, 500, 400, 600, 300, null, null, 6, 1); // 2. 读取起始点 X const startX = arc.getState_StartX(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.sch_PrimitiveArc.delete([arc.getState_PrimitiveId()]); console.log('startX:', startX); ``` -------------------------------- ### Get current language and check Chinese environment Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sys_i18n.getcurrentlanguage.html JavaScript example that retrieves the current language using eda.sys_I18n.getCurrentLanguage() and checks whether it is Chinese by testing if the returned string starts with 'zh'. ```javascript // 1. 获取当前显示语言 const current = await eda.sys_I18n.getCurrentLanguage(); // 2. 判断当前是否中文环境 console.log('当前语言:', current); console.log('是否中文环境:', current.startsWith('zh')); ``` -------------------------------- ### JavaScript example: create wire, set network, and verify Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivewire.setstate_net.html This example creates a test wire on network 'SIG_A', reads its network, switches to async mode, sets the network to 'SIG_B', and then refetches the wire to confirm the change. It uses random coordinates to avoid overlap with previous test wires. ```javascript // 1. 生成本次运行专用的坐标,避免与之前保留的测试导线重合 const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); // 2. 创建一条属于 SIG_A 网络的测试导线(SCH 坐标单位 10mil) const wire = await eda.sch_PrimitiveWire.create([x, y, x + 400, y], 'SIG_A'); // 3. 读取修改前的网络名称 const before = wire.getState_Net(); // 4. 切换异步模式并改为 SIG_B const asyncWire = wire.toAsync(); asyncWire.setState_Net('SIG_B'); await asyncWire.done(); // 5. 从画布重新读取,确认修改已生效(保留现场供观察) const refetched = await eda.sch_PrimitiveWire.get(wire.getState_PrimitiveId()); console.log('net:', before, '→', refetched.getState_Net()); ``` -------------------------------- ### Querying all design rule configurations Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_drc.getallruleconfigurations.html Example showing how to query all design rule configurations including system settings and logging the results. ```javascript // 1. 查询全部设计规则配置(含系统配置) const all = await eda.pcb_Drc.getAllRuleConfigurations(true); // 2. 输出配置数量和名称 console.log('count:', all.length); all.forEach((c, i) => { console.log(`[${i}] name:`, c.name); }); ``` -------------------------------- ### getAllPrimitiveId() JavaScript example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_primitivecomponent.getallprimitiveid.html Shows how to call getAllPrimitiveId() with no arguments to get all component primitive IDs, and with a layer argument to filter by top layer. Includes setup and cleanup of a test component. ```javascript // 1. 放置一个测试器件作为过滤参照: // 按立创编号从系统库精确反查器件,返回项不含 libraryUuid,需补上才能用于 create const devices = await eda.lib_Device.searchByProperties({ supplierId: 'C1523' }, undefined, undefined, undefined, 5, 1); const sysLibUuid = await eda.lib_LibrariesList.getSystemLibraryUuid(); const comp = await eda.pcb_PrimitiveComponent.create({ libraryUuid: sysLibUuid, uuid: devices[0].uuid }, 1, 5000, 5000); const compId = comp.getState_PrimitiveId(); // 2. 不带参数:获取全部器件的图元 ID const allIds = await eda.pcb_PrimitiveComponent.getAllPrimitiveId(); // 3. 按层过滤:只取顶层(1)器件的图元 ID const topIds = await eda.pcb_PrimitiveComponent.getAllPrimitiveId(1); // 4. 清理测试器件 await eda.pcb_PrimitiveComponent.delete([compId]); console.log('total ids:', allIds.length); console.log('top layer ids:', topIds.length); console.log('fixture included:', allIds.includes(compId)); console.log('firstId:', allIds[0]); ``` -------------------------------- ### Create a network port example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sch_primitivecomponent.createnetport.html Example demonstrating how to generate random coordinates and create an input network port, followed by logging the component's state. ```javascript // 1. 随机坐标避免与画布已有图元重合(SCH 坐标单位 10mil) const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); // 2. 创建输入方向的端口,网络名为 SIG_IN const port = await eda.sch_PrimitiveComponent.createNetPort( 'IN', // 端口方向:'IN' / 'OUT' / 'BI' '嘉立创示例_SIG', // 网络名称 x, // 坐标 X y, // 坐标 Y 0, // 旋转角度 false // 是否镜像 ); // 3. 创建类保留现场,供在画布上观察端口样式 console.log('primitiveId:', port.getState_PrimitiveId()); console.log('net:', port.getState_Net()); console.log('componentType:', port.getState_ComponentType()); ``` -------------------------------- ### JavaScript example: set start X of an arc Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitivearc.setstate_startx.html This example creates a test arc, reads its start X, switches to async mode, sets the start X to x+300, and then refetches the arc to confirm the change. It logs the before and after values. ```javascript // 1. 生成本次运行专用的坐标,避免与之前保留的测试圆弧重合 const x = 6000 + (Math.floor(Math.random() * 100000)); const y = 2000 + (Math.floor(Math.random() * 100000)); // 2. 创建一段测试圆弧,起点 (x, y) const arc = await eda.pcb_PrimitiveArc.create('', 1, x, y, x + 500, y + 300, 90, 10, 1, false); // 3. 读取修改前的起点 X const before = arc.getState_StartX(); // 4. 切换异步模式并平移起点 X(右移 300mil) const asyncArc = arc.toAsync(); asyncArc.setState_StartX(x + 300); await asyncArc.done(); // 5. 从画布重新读取,确认修改已生效(保留现场供观察) const refetched = await eda.pcb_PrimitiveArc.get(arc.getState_PrimitiveId()); const after = refetched.getState_StartX(); console.log('startX:', before, '→', after); ``` -------------------------------- ### setState_StartY() usage example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivearc.setstate_starty.html Example usage of setState_StartY. It creates a test arc, reads the original start Y, switches to async mode, sets the new start Y, and verifies the change by refetching from the canvas. ```javascript // 1. 生成本次运行专用的坐标,避免与之前保留的测试圆弧重合 const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); // 2. 创建一段测试圆弧,起点 (x, y)(SCH 坐标单位 10mil) const arc = await eda.sch_PrimitiveArc.create(x, y, x + 100, y + 100, x + 200, y, null, null, 6, 1); // 3. 读取修改前的起点 Y const before = arc.getState_StartY(); // 4. 切换异步模式并将起点 Y 上移 60 const asyncArc = arc.toAsync(); asyncArc.setState_StartY(y - 60); await asyncArc.done(); // 5. 从画布重新读取,确认修改已生效(保留现场供观察) const refetched = await eda.sch_PrimitiveArc.get(arc.getState_PrimitiveId()); console.log('startY:', before, '→', refetched.getState_StartY()); ``` -------------------------------- ### Writing and updating extension user configurations Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sys_storage.setextensionuserconfig.html Example showing how to create a new configuration, update an existing one, and clean up the configuration. ```javascript // 1. 写入一条新配置(key 不存在时自动新建) const created = await eda.sys_Storage.setExtensionUserConfig('嘉立创示例_主题', '深色'); // 2. 用同一个 key 再次写入,覆盖旧值 const updated = await eda.sys_Storage.setExtensionUserConfig('嘉立创示例_主题', '浅色'); // 3. 清理演示配置,还原存储现场 await eda.sys_Storage.deleteExtensionUserConfig('嘉立创示例_主题'); console.log('新建配置结果:', created); console.log('覆盖写入结果:', updated); ``` -------------------------------- ### Example: reading start Y position of an arc Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitivearc.getstate_starty.html JavaScript example that creates a test arc, reads its start Y position using getState_StartY(), then deletes the test primitive. Logs the startY value to the console. ```javascript // 1. 创建一段测试圆弧,起点 (1000, 1000)(PCB 坐标单位 mil) const arc = await eda.pcb_PrimitiveArc.create('', 1, 1000, 1000, 1500, 1300, 90, 10, 1, false); // 2. 读取起始位置 Y const startY = arc.getState_StartY(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.pcb_PrimitiveArc.delete([arc.getState_PrimitiveId()]); console.log('startY:', startY); ``` -------------------------------- ### Querying All Network Classes Example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_drc.getallnetclasses.html An example demonstrating how to create a test network class, retrieve all network classes, and clean up the test class. ```javascript // 1. 建一个测试网络类作为查询对象 await eda.pcb_Drc.createNetClass('嘉立创示例_查询网络类', [], { r: 255, g: 0, b: 0, alpha: 1 }); // 2. 查询所有网络类 const classes = await eda.pcb_Drc.getAllNetClasses(); console.log('count:', classes.length); classes.forEach((c, i) => { console.log(`[${i}] name:`, c.name); }); // 3. 清理测试网络类(查询类清理现场) await eda.pcb_Drc.deleteNetClass('嘉立创示例_查询网络类'); ``` -------------------------------- ### PCB_PrimitiveImage.get() usage example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_primitiveimage.get.html Example usage of the get() method. It creates two test images, then calls get() with a single ID string and with an array of IDs, demonstrating both return types. The example also cleans up the test primitives with delete() and logs properties of the returned objects. ```javascript // 1. 创建两个测试图像(随机坐标避免重合,轮廓用折线多边形) const x = 2000 + Math.floor(Math.random() * 100000); const y = 2000 + Math.floor(Math.random() * 100000); const cp = eda.pcb_MathPolygon.createComplexPolygon([0, 0, 'L', 200, 0, 200, 150, 0, 150]); const image1 = await eda.pcb_PrimitiveImage.create(x, y, cp, 1, 400, 300, 0, false, false); const image2 = await eda.pcb_PrimitiveImage.create(x, y + 1000, cp, 1, 400, 300, 0, false, false); // 2. 传单个 ID 字符串,返回单个图像对象 const single = await eda.pcb_PrimitiveImage.get(image1.getState_PrimitiveId()); // 3. 传 ID 数组,返回图像对象数组 const arr = await eda.pcb_PrimitiveImage.get([ image1.getState_PrimitiveId(), image2.getState_PrimitiveId() ]); // 4. 清理测试图元(查询类需要清理) await eda.pcb_PrimitiveImage.delete([ image1.getState_PrimitiveId(), image2.getState_PrimitiveId() ]); console.log('single layer:', single.getState_Layer()); console.log('single width:', single.getState_Width()); console.log('array length:', arr.length); console.log('image2 rotation:', arr[1].getState_Rotation()); ``` -------------------------------- ### Moving a project to a folder example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.dmt_project.moveprojecttofolder.html Demonstrates moving a project to a new folder, verifying the move, and restoring the project to its original location. ```javascript // 1. 记录当前工程的位置,作为移动后恢复的锚点 const info = await eda.dmt_Project.getCurrentProjectInfo(); const projectUuid = info.uuid; const teamUuid = info.teamUuid; const originalFolderUuid = info.folderUuid; // 可能为 undefined(团队根目录) // 2. 创建目标文件夹,等待 1.5s 让工作区同步 const targetFolderUuid = await eda.dmt_Folder.createFolder('嘉立创示例_目标文件夹', teamUuid); await new Promise(r => setTimeout(r, 1500)); // 3. 把当前工程移到目标文件夹下 const moved = await eda.dmt_Project.moveProjectToFolder(projectUuid, targetFolderUuid); await new Promise(r => setTimeout(r, 1000)); // 4. 回读验证工程已落到目标文件夹 const after = await eda.dmt_Project.getCurrentProjectInfo(); const folderChanged = after?.folderUuid === targetFolderUuid; // 5. 恢复:移回原位置(原为根目录时传 undefined) const restored = await eda.dmt_Project.moveProjectToFolder(projectUuid, originalFolderUuid); await new Promise(r => setTimeout(r, 1000)); console.log('moved:', moved); console.log('folderChanged:', folderChanged); console.log('restored:', restored); ``` -------------------------------- ### Example: move PCB to split screen and back Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.dmt_editorcontrol.movedocumenttosplitscreen.html JavaScript example showing how to normalize layout, open documents, create a split screen, move a PCB tab back to the source split screen, verify tabs, and clean up. ```javascript // 1. 归一化布局后打开两个文档,把 PCB 拆到新分屏 await eda.dmt_EditorControl.mergeAllDocumentFromSplitScreen(); const pages = await eda.dmt_Schematic.getAllSchematicPagesInfo(); const pcbs = await eda.dmt_Pcb.getAllPcbsInfo(); await eda.dmt_EditorControl.openDocument(pages[0].uuid); const tabPcb = await eda.dmt_EditorControl.openDocument(pcbs[0].uuid); const split = await eda.dmt_EditorControl.createSplitScreen('vertical', tabPcb); // 2. 把 PCB 标签页移回源分屏 const moved = await eda.dmt_EditorControl.moveDocumentToSplitScreen(tabPcb, split.sourceSplitScreenId); console.log('moved:', moved); // 3. 回读源分屏标签页,确认两个标签页又同处一个分屏 const tabs = await eda.dmt_EditorControl.getTabsBySplitScreenId(split.sourceSplitScreenId); console.log('source split tabs:', tabs.map(t => t.title)); // 4. 清理:合并残余分屏,恢复单屏布局 const mergedBack = await eda.dmt_EditorControl.mergeAllDocumentFromSplitScreen(); console.log('mergedBack:', mergedBack); ``` -------------------------------- ### Usage example for getShortcutKeys Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sys_shortcutkey.getshortcutkeys.html Shows how to query non-system shortcuts and all shortcuts including system, and how to inspect a single shortcut's structure. ```javascript // 1. 只查非系统快捷键(扩展注册的),列表精简便于观察 const custom = await eda.sys_ShortcutKey.getShortcutKeys(); console.log('非系统快捷键数量:', custom.length); // 2. 连同系统快捷键一起查(用于完整键位冲突检测) const all = await eda.sys_ShortcutKey.getShortcutKeys(true); console.log('含系统快捷键总数:', all.length); // 3. 观察单条数据结构:shortcutKey 是键位数组,title 是名称, // documentType 是生效页面,scene 是生效场景 const sample = all[0]; console.log('首条快捷键:', JSON.stringify(sample)); ``` -------------------------------- ### Get component designator example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivecomponent.getstate_designator.html Example demonstrating how to create a component, retrieve its designator, and then delete the component. ```javascript // 1. 放置一个测试器件(SCH 坐标单位 10mil) const devices = await eda.lib_Device.search('C0402'); const comp = await eda.sch_PrimitiveComponent.create(devices[0], 600, 600); const compId = comp.getState_PrimitiveId(); // 2. 读取位号(未分配时是带问号的临时位号,如 C?) const designator = comp.getState_Designator(); // 3. 清理测试器件(查询类需要清理) await eda.sch_PrimitiveComponent.delete([compId]); console.log('designator:', designator); ``` -------------------------------- ### PCB_PrimitiveDimension.get() example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_primitivedimension.get.html Example usage of the get method. It creates two test dimensions, then calls get with a single ID string and with an array of IDs, and finally cleans up the test primitives. The example logs the dimension type and unit of the single result and the array length and unit of the second array element. ```javascript // 1. 创建两个测试标注(随机坐标避免重合) const x = 2000 + Math.floor(Math.random() * 100000); const y = 2000 + Math.floor(Math.random() * 100000); const dim1 = await eda.pcb_PrimitiveDimension.create( 'Length Dimension', [x, y, x, y - 200, x + 2000, y - 200, x + 2000, y], 3, 'mm' ); const dim2 = await eda.pcb_PrimitiveDimension.create( 'Length Dimension', [x, y + 1000, x, y + 800, x + 2000, y + 800, x + 2000, y + 1000], 3, 'mil' ); // 2. 传单个 ID 字符串,返回单个标注对象 const single = await eda.pcb_PrimitiveDimension.get(dim1.getState_PrimitiveId()); // 3. 传 ID 数组,返回标注对象数组 const arr = await eda.pcb_PrimitiveDimension.get([ dim1.getState_PrimitiveId(), dim2.getState_PrimitiveId() ]); // 4. 清理测试图元(查询类需要清理) await eda.pcb_PrimitiveDimension.delete([ dim1.getState_PrimitiveId(), dim2.getState_PrimitiveId() ]); console.log('single dimensionType:', single.getState_DimensionType()); console.log('single unit:', single.getState_Unit()); console.log('array length:', arr.length); console.log('dim2 unit:', arr[1].getState_Unit()); ``` -------------------------------- ### Highlighting a network example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_net.highlightnet.html Example demonstrating how to create a via with a network name, highlight that network, and then clean up the test primitive. ```javascript // 1. 创建带网络名的过孔,让 PCB 中出现可操作的网络 const via = await eda.pcb_PrimitiveVia.create('嘉立创示例_NET1', 2000, 2000, 20, 40); // 2. 高亮该网络(画布上此网络的图元高亮显示) const highlighted = await eda.pcb_Net.highlightNet('嘉立创示例_NET1'); // 3. 清理测试图元(操作类需要清理) await eda.pcb_PrimitiveVia.delete([via.getState_PrimitiveId()]); console.log('highlighted:', highlighted); ``` -------------------------------- ### JavaScript example: create pad, set net, and verify Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitivepad.setstate_net.html This example creates a pad without a net, sets a net asynchronously, and then reads the pad from the canvas to confirm the net was applied. It uses the PCB editor API and logs the before and after net values. ```javascript // 1. 生成本次运行专用的坐标,创建一个无网络的贴片焊盘 const x = 3000 + Math.floor(Math.random() * 100000); const pad = await eda.pcb_PrimitivePad.create(1, '1', x, 3000, 0, ['ELLIPSE', 60, 60], '', null, 0, 0, 0, false, 0); const before = pad.getState_Net(); // 2. 异步模式下挂载网络并提交 const a = pad.toAsync(); a.setState_Net('嘉立创示例_NET1'); await a.done(); // 3. 从画布重新读取,确认网络已挂载(保留现场供观察) const ref = await eda.pcb_PrimitivePad.get(pad.getState_PrimitiveId()); console.log('net:', before, '→', ref.getState_Net()); ``` -------------------------------- ### setState_StartX example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivearc.setstate_startx.html Example usage of setState_StartX. It creates a test arc, reads the original start X, switches to async mode, sets the start X to x-60, and then refetches the arc to confirm the change. The example uses random coordinates to avoid overlap with previous test arcs and logs the before/after values. ```javascript // 1. 生成本次运行专用的坐标,避免与之前保留的测试圆弧重合 const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); // 2. 创建一段测试圆弧,起点 (x, y)(SCH 坐标单位 10mil) const arc = await eda.sch_PrimitiveArc.create(x, y, x + 100, y + 100, x + 200, y, null, null, 6, 1); // 3. 读取修改前的起点 X const before = arc.getState_StartX(); // 4. 切换异步模式并将起点 X 左移 60 const asyncArc = arc.toAsync(); asyncArc.setState_StartX(x - 60); await asyncArc.done(); // 5. 从画布重新读取,确认修改已生效(保留现场供观察) const refetched = await eda.sch_PrimitiveArc.get(arc.getState_PrimitiveId()); console.log('startX:', before, '→', refetched.getState_StartX()); ``` -------------------------------- ### JavaScript example: create wires and call getAll() Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sch_primitivewire.getall.html Creates two test wires on different networks, then calls getAll() without arguments to fetch all wires and with 'SIG_A' to filter by network. Finally deletes the test wires and logs results. ```javascript // 1. 创建两条测试导线,分别属于不同网络(随机坐标避免重合,SCH 坐标单位 10mil) const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); const wire1 = await eda.sch_PrimitiveWire.create([x, y, x + 400, y], 'SIG_A'); const wire2 = await eda.sch_PrimitiveWire.create([x, y + 200, x + 400, y + 200], 'SIG_B'); const wire1Id = wire1.getState_PrimitiveId(); // 2. 不传参数,获取当前原理图页上的全部导线 const all = await eda.sch_PrimitiveWire.getAll(); // 3. 传网络名称,只获取该网络的导线 const onlyA = await eda.sch_PrimitiveWire.getAll('SIG_A'); // 4. 清理测试图元(查询类需要清理) await eda.sch_PrimitiveWire.delete([wire1.getState_PrimitiveId(), wire2.getState_PrimitiveId()]); console.log('total wires:', all.length); console.log('marker wire found:', all.some(w => w.getState_PrimitiveId() === wire1Id)); console.log('SIG_A wires:', onlyA.length); console.log('SIG_A all same net:', onlyA.every(w => w.getState_Net() === 'SIG_A')); ``` -------------------------------- ### deleteByIndex JavaScript usage example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.lib_classification.deletebyindex.html Example showing how to get the personal library UUID, create a test classification, and delete it using deleteByIndex. The example logs the name and deletion result. ```javascript // 1. 获取个人库 UUID const libraryUuid = await eda.lib_LibrariesList.getPersonalLibraryUuid(); // 2. 创建一个测试分类作为删除对象(复用模块库,ELIB_LibraryType.CBB = '1') const name = `嘉立创示例_待删除分类_${Date.now()}`; const index = await eda.lib_Classification.createPrimary(libraryUuid, '1', name); // 3. 按索引对象删除该分类 const deleted = await eda.lib_Classification.deleteByIndex(index); // 删除类保留现场(分类已不存在,库面板中可确认) console.log('name:', name); console.log('deleted:', deleted); ``` -------------------------------- ### Example: get classification names by UUID Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.lib_classification.getnamebyuuid.html Example usage of getNameByUuid. It first gets the personal library UUID, creates two test classifications, then calls getNameByUuid with only the primary UUID and with both UUIDs, logs the results, and finally cleans up by deleting the primary classification. ```javascript // 1. 获取个人库 UUID const libraryUuid = await eda.lib_LibrariesList.getPersonalLibraryUuid(); // 2. 创建两级测试分类(复用模块库,ELIB_LibraryType.CBB = '1') const tag = Date.now(); const primaryName = `嘉立创示例_按UUID查名一级_${tag}`; const secondaryName = `嘉立创示例_按UUID查名二级_${tag}`; const primaryIndex = await eda.lib_Classification.createPrimary(libraryUuid, '1', primaryName); const secondaryIndex = await eda.lib_Classification.createSecondary( libraryUuid, '1', primaryIndex.primaryClassificationUuid, secondaryName ); // 3. 只传一级 UUID:返回一级名称 const primaryNames = await eda.lib_Classification.getNameByUuid( libraryUuid, '1', primaryIndex.primaryClassificationUuid ); // 4. 传一级 + 二级 UUID:两级名称都返回 const bothNames = await eda.lib_Classification.getNameByUuid( libraryUuid, '1', primaryIndex.primaryClassificationUuid, secondaryIndex.secondaryClassificationUuid ); // 5. 清理测试分类(查询类需要清理) await eda.lib_Classification.deleteByUuid(libraryUuid, primaryIndex.primaryClassificationUuid); console.log('primaryNames:', primaryNames); console.log('bothNames:', bothNames); ``` -------------------------------- ### Example: copy a PCB and verify Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.dmt_pcb.copypcb.html JavaScript example that creates a source PCB, waits 1.5 seconds for synchronization, copies it, reads back the copy info, and cleans up by deleting both PCBs. The source PCB must be landed in the workspace before copying. ```javascript // 1. 创建一个专用源 PCB 并等 1.5s 同步(复制前源 PCB 必须已在工作区落地) const sourceUuid = await eda.dmt_Pcb.createPcb(); await new Promise(r => setTimeout(r, 1500)); // 2. 复制源 PCB,返回副本 UUID const copiedUuid = await eda.dmt_Pcb.copyPcb(sourceUuid); await new Promise(r => setTimeout(r, 1500)); // 3. 回读副本,确认名称与归属 const copyInfo = await eda.dmt_Pcb.getPcbInfo(copiedUuid); console.log('copiedUuid:', copiedUuid); console.log('copyName:', copyInfo?.name); console.log('copyParentBoardName:', copyInfo?.parentBoardName); // 4. 清理本例创建的两块 PCB(先删副本再删源),保持工程整洁 const deletedCopy = await eda.dmt_Pcb.deletePcb(copiedUuid); console.log('deleted:', deletedCopy); const deletedSource = await eda.dmt_Pcb.deletePcb(sourceUuid); console.log('deleted:', deletedSource); ``` -------------------------------- ### Get line width example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitiveline.getstate_linewidth.html Example demonstrating how to create a line, retrieve its line width using getState_LineWidth, and then delete the test primitive. ```javascript // 1. 创建一条 10mil 线宽的测试直线 const line = await eda.pcb_PrimitiveLine.create('', 1, 1000, 1000, 1600, 1000, 10); // 2. 读取线宽 const lineWidth = line.getState_LineWidth(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.pcb_PrimitiveLine.delete([line.getState_PrimitiveId()]); console.log('lineWidth:', lineWidth); ``` -------------------------------- ### JavaScript example: create bus, call getAll(), and clean up Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sch_primitivebus.getall.html Demonstrates creating a test bus with random coordinates, retrieving all buses with getAll(), and deleting the test bus. Logs the total count and whether the marker bus is found. ```javascript // 1. 创建一条测试总线作为查找目标(随机坐标避免重合,SCH 坐标单位 10mil) const x = 2000 + Math.floor(Math.random() * 8000); const y = 2000 + Math.floor(Math.random() * 8000); const bus = await eda.sch_PrimitiveBus.create('DATA[0..7]', [x, y, x + 400, y]); const busId = bus.getState_PrimitiveId(); // 2. 获取当前原理图页上的全部总线 const all = await eda.sch_PrimitiveBus.getAll(); // 3. 清理测试图元(查询类需要清理) await eda.sch_PrimitiveBus.delete([busId]); console.log('total buses:', all.length); console.log('marker bus found:', all.some(b => b.getState_PrimitiveId() === busId)); ``` -------------------------------- ### setState_StartX(startX) Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitiveobject.html **_(BETA)_** 设置属性状态:起点坐标 X。 ```APIDOC ## setState_StartX(startX) ### Description **_(BETA)_** 设置属性状态:起点坐标 X。 ### Method setState_StartX(startX) ### Parameters - **startX** (number) - Required - 起点坐标 X。 ### Returns 无返回值。 ``` -------------------------------- ### Get component X coordinate example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitivecomponent.getstate_x.html Example demonstrating how to create a component, retrieve its X coordinate using getState_X, and then delete the component. ```javascript // 1. 放置一个测试器件 const devices = await eda.lib_Device.search('C0402'); const comp = await eda.pcb_PrimitiveComponent.create(devices[0], 1, 5000, 5000); // 2. 读取锚点 X 坐标 const x = comp.getState_X(); // 3. 清理测试器件 await eda.pcb_PrimitiveComponent.delete([comp.getState_PrimitiveId()]); console.log('x:', x); ``` -------------------------------- ### Example: create pad, set pad number, and verify Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.ipcb_primitivepad.setstate_padnumber.html Shows how to create a pad, change its pad number asynchronously, and verify the update by reading the pad back from the canvas. The example uses a random coordinate and logs the before and after values. ```javascript // 1. 生成本次运行专用的坐标,创建一个编号为 '1' 的贴片焊盘 const x = 3000 + Math.floor(Math.random() * 100000); const pad = await eda.pcb_PrimitivePad.create(1, '1', x, 3000, 0, ['ELLIPSE', 60, 60], '', null, 0, 0, 0, false, 0); const before = pad.getState_PadNumber(); // 2. 异步模式下修改编号并提交 const a = pad.toAsync(); a.setState_PadNumber('嘉立创示例_A1'); await a.done(); // 3. 从画布重新读取,确认编号已更新(保留现场供观察) const ref = await eda.pcb_PrimitivePad.get(pad.getState_PrimitiveId()); console.log('padNumber:', before, '→', ref.getState_PadNumber()); ``` -------------------------------- ### SYS_ClientUrl.request() GET example Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.sys_clienturl.request.html Example of making a GET request with SYS_ClientUrl.request. The response is a standard fetch Response object; use response.text() to read the body. Requires CORS enabled on the target site and the extension's external interaction permission, otherwise it will throw an Error. ```javascript // 1. 发起 GET 请求(本例用本机桥接地址演示,实际使用时换成自己的服务地址) const response = await eda.sys_ClientUrl.request('http://localhost:49620/health', 'GET'); // 2. 读取响应状态码 console.log('状态码:', response.status); // 3. 读取响应内容(Response 是标准 fetch 返回值,用法与浏览器一致) const body = await response.text(); console.log('响应内容:', body); ``` -------------------------------- ### getState_StartX() Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.isch_primitivearc.getstate_startx.html 获取属性状态:起始点 X。 ```APIDOC ## getState_StartX() ### Description 获取属性状态:起始点 X。 ### Method function ### Signature ```typescript function getState_StartX(): number; ``` ### Parameters 无参数。 ### Return Value - **number** - 起始点 X ### Example ```javascript // 1. 创建一段测试圆弧,起点 (400, 300)(SCH 坐标单位 10mil) const arc = await eda.sch_PrimitiveArc.create(400, 300, 500, 400, 600, 300, null, null, 6, 1); // 2. 读取起始点 X const startX = arc.getState_StartX(); // 3. 清理测试图元(查询类案例不留测试对象) await eda.sch_PrimitiveArc.delete([arc.getState_PrimitiveId()]); console.log('startX:', startX); ``` ``` -------------------------------- ### Example: get() with single ID and array of IDs Source: https://prodocs.lceda.cn/cn/api/reference/pro-api.pcb_primitiveobject.get.html Example usage of the get() method. It creates two test embedded objects, retrieves a single object by passing a string ID, retrieves an array by passing an array of IDs, and then cleans up the test primitives. The example logs the width of the single object, the length of the array, and the file name of the second object in the array. ```javascript // 1. 创建两个测试内嵌对象(随机坐标避免重合),使用 4x4 像素 PNG 的 data URI const x = 2000 + Math.floor(Math.random() * 100000); const y = 2000 + Math.floor(Math.random() * 100000); const binaryData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAEElEQVR4nGP4z8AARwzEcQCukw/x0F8jngAAAABJRU5ErkJggg=='; const obj1 = await eda.pcb_PrimitiveObject.create(3, x, y, binaryData, 400, 300, 0, false, 'logo1.png', false); const obj2 = await eda.pcb_PrimitiveObject.create(3, x, y + 500, binaryData, 200, 150, 0, false, 'logo2.png', false); // 2. 传单个 ID 字符串,返回单个内嵌对象 const single = await eda.pcb_PrimitiveObject.get(obj1.getState_PrimitiveId()); // 3. 传 ID 数组,返回内嵌对象数组(混入未匹配的 ID 不影响其它图元返回) const arr = await eda.pcb_PrimitiveObject.get([obj1.getState_PrimitiveId(), obj2.getState_PrimitiveId()]); // 4. 清理测试图元(查询类需要清理) await eda.pcb_PrimitiveObject.delete([obj1.getState_PrimitiveId(), obj2.getState_PrimitiveId()]); console.log('single width:', single.getState_Width()); console.log('array length:', arr.length); console.log('obj2 fileName:', arr[1].getState_FileName()); ```