Home > SCH_PrimitiveObject > create
SCH_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(
content: File | string,
startX: number,
startY: number,
width?: number,
height?: number,
rotation?: number,
mirror?: boolean,
fileName?: string,
): Promise<ISCH_PrimitiveObject | undefined>;1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Parameters
Parameter | Type | Description |
|---|---|---|
content | File | string | Object content |
startX | number | Start point coordinates X |
startY | number | Start point coordinates Y |
width | number | (Optional) Width |
height | number | (Optional) Height |
rotation | number | (Optional) Rotation angle |
mirror | boolean | (Optional) Whether it is mirrored |
fileName | string | (Optional) File name |
Returns
Promise<ISCH_PrimitiveObject | undefined>
Binary embedded object primitive object
Example
javascript
// 1. 生成随机放置坐标,避免与画布上已有的内嵌对象重合(SCH 坐标单位 10mil)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 准备 4x4 像素 PNG 的 data URI(content 实测也接受裸 base64,data URI 带格式头更易读)
const png = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAEElEQVR4nGP4z8AARwzEcQCukw/x0F8jngAAAABJRU5ErkJggg==';
// 3. 在起点(x, y)放置图片:宽 400、高 300,不旋转、不镜像,文件名 logo.png
const obj = await eda.sch_PrimitiveObject.create(png, x, y, 400, 300, 0, false, 'logo.png');
// 4. 创建类保留现场,不删除图元(getState_Content 返回数据内容,用长度表示)
console.log('primitiveId:', obj.getState_PrimitiveId());
console.log('primitiveType:', obj.getState_PrimitiveType());
console.log('startX:', obj.getState_StartX(), 'startY:', obj.getState_StartY());
console.log('width:', obj.getState_Width(), 'height:', obj.getState_Height());
console.log('fileName:', obj.getState_FileName());
console.log('content length:', obj.getState_Content().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