Home > PCB_Layer > addCustomLayer
PCB_Layer.addCustomLayer() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
新增自定义层
签名
typescript
function addCustomLayer(): Promise<TPCB_LayersOfCustom | undefined>;1
返回值
Promise<TPCB_LayersOfCustom | undefined>
新增的自定义层的图层 ID,如若为 undefined 则为新增失败,可能是自定义层数量已达到上限
示例
javascript
// 1. 先移除历史运行遗留的自定义层,保证案例可以反复执行
const layers = await eda.pcb_Layer.getAllLayers();
for (const item of layers.filter(l => l.type === 'CUSTOM')) {
await eda.pcb_Layer.removeLayer(item.id);
}
// 2. 新增自定义层,返回新层的图层 ID(CUSTOM_1=71 起顺延分配)
const customLayerId = await eda.pcb_Layer.addCustomLayer();
// 3. 从图层列表确认新层已存在(保留现场,可在图层面板观察)
const after = await eda.pcb_Layer.getAllLayers();
const newLayer = after.find(l => l.id === customLayerId);
console.log('customLayerId:', customLayerId);
console.log('newLayerName:', newLayer?.name);
console.log('customLayerCount:', after.filter(l => l.type === 'CUSTOM').length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16