Home > PCB_Layer > addCustomLayer
PCB_Layer.addCustomLayer() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Add a custom layer
Signature
typescript
function addCustomLayer(): Promise<TPCB_LayersOfCustom | undefined>;1
Returns
Promise<TPCB_LayersOfCustom | undefined>
The layer ID of the newly added custom layer. If it is undefined, the addition failed, possibly because the number of custom layers has reached the upper limit
Example
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