Home > PCB_PrimitiveObject > create
PCB_PrimitiveObject.create() 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.
Create Binary embedded object
Signature
typescript
function create(
layer: TPCB_LayersOfObject,
topLeftX: number,
topLeftY: number,
binaryData: string,
width: number,
height: number,
rotation?: number,
mirror?: boolean,
fileName?: string,
primitiveLock?: boolean,
): Promise<IPCB_PrimitiveObject | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Parameters
Parameter | Type | Description |
|---|---|---|
layer | Layer | |
topLeftX | number | Top-left point X |
topLeftY | number | Top-left point Y |
binaryData | string | Binary data |
width | number | Width |
height | number | Height |
rotation | number | (Optional) Rotation angle |
mirror | boolean | (Optional) Whether it is horizontally mirrored |
fileName | string | (Optional) File name |
primitiveLock | boolean | (Optional) Whether it is locked |
Returns
Promise<IPCB_PrimitiveObject | undefined>
- binary embedded object primitive object
Example
javascript
// 1. 生成随机放置坐标,避免与画布上已有的内嵌对象重合
const x = 2000 + Math.floor(Math.random() * 100000);
const y = 2000 + Math.floor(Math.random() * 100000);
// 2. 准备 4x4 像素 PNG 的 data URI(binaryData 必须是 data URI 格式,裸 base64 会创建失败)
const binaryData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAEElEQVR4nGP4z8AARwzEcQCukw/x0F8jngAAAABJRU5ErkJggg==';
// 3. 在顶层丝印(3)放置图片:左上角(x, y),宽 400、高 300,不旋转、不镜像、不锁定
const obj = await eda.pcb_PrimitiveObject.create(3, x, y, binaryData, 400, 300, 0, false, 'logo.png', false);
// 4. 创建类保留现场,不删除图元(getState_BinaryData 返回数据 hash,用长度表示)
console.log('primitiveId:', obj.getState_PrimitiveId());
console.log('primitiveType:', obj.getState_PrimitiveType());
console.log('layer:', obj.getState_Layer());
console.log('width:', obj.getState_Width(), 'height:', obj.getState_Height());
console.log('fileName:', obj.getState_FileName());
console.log('binaryData hash length:', obj.getState_BinaryData().length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17