Home > PCB_Document > setCanvasOrigin
PCB_Document.setCanvasOrigin() method
Set the offset coordinate of the canvas origin relative to the data origin
Signature
function setCanvasOrigin(offsetX: number, offsetY: number): Promise<boolean>;Parameters
Parameter | Type | Description |
|---|---|---|
offsetX | number | X coordinate offset of the canvas origin relative to the data origin |
offsetY | number | Y coordinate offset of the canvas origin relative to the data origin |
Returns
Promise<boolean>
Whether the operation is successful
Remarks
The coordinates displayed on the EasyEDA Pro front end are all relative to the canvas origin;
The EasyEDA Pro API uses the data origin;
If you want the front-end canvas coordinate to be consistent with the data during API operations, it is recommended to call this method and set the offset to zero, i.e. setCanvasOrigin(0, 0);
The units here are data-level units, which are equivalent to mil on the canvas level in span
Example
// 1. 创建测试 PCB 并打开(原点设置作用于当前激活的 PCB)
const pcbUuid = await eda.dmt_Pcb.createPcb();
await new Promise(r => setTimeout(r, 1500));
await eda.dmt_EditorControl.openDocument(pcbUuid);
await new Promise(r => setTimeout(r, 1000));
// 2. 设置画布原点偏移为 (50, 100)
const set = await eda.pcb_Document.setCanvasOrigin(50, 100);
console.log('set:', set);
// 3. 读回偏移验证已生效
const origin = await eda.pcb_Document.getCanvasOrigin();
console.log('origin:', JSON.stringify(origin));
// 4. 清理测试 PCB(偏移随文档一起删除)
await eda.dmt_Pcb.deletePcb(pcbUuid);2
3
4
5
6
7
8
9
10
11
12
13
14
15
16