Home > DMT_EditorControl > zoomToSelectedPrimitives
DMT_EditorControl.zoomToSelectedPrimitives() 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.
Zoom to the selected primitives (fit selection)
Signature
typescript
function zoomToSelectedPrimitives(
tabId?: string,
): Promise<{ left: number; right: number; top: number; bottom: number } | false>;1
2
3
2
3
Parameters
Parameter | Type | Description |
|---|---|---|
tabId | string | (Optional) Tab ID. If not passed in, the canvas with the last input focus will be used |
Returns
Promise<{ left: number; right: number; top: number; bottom: number } | false>
Region data after zooming. false indicates that the canvas does not support the zoom operation or the tabId does not exist
Remarks
In the returned data, the coordinate unit span of the schematic and symbol canvases is 0.01inch, and that of the PCB and footprint canvases is mil
Example
javascript
// 1. 打开原理图页,创建一个文本图元作为选中目标
const pages = await eda.dmt_Schematic.getAllSchematicPagesInfo();
const tabId = await eda.dmt_EditorControl.openDocument(pages[0].uuid);
const text = await eda.sch_PrimitiveText.create(100, 80, '嘉立创示例_缩放目标');
// 2. 以图元 ID 建立选中状态
const selected = await eda.sch_SelectControl.doSelectPrimitives([text.getState_PrimitiveId()]);
console.log('selected:', selected);
// 3. 缩放到选中的图元,返回可视区域边界
const bounds = await eda.dmt_EditorControl.zoomToSelectedPrimitives(tabId);
console.log('bounds:', bounds);
// 4. 清理:取消选中并删除测试图元
await eda.sch_SelectControl.clearSelected();
await eda.sch_PrimitiveText.delete([text.getState_PrimitiveId()]);
console.log('cleaned');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