Home > SCH_PrimitiveWire > create
SCH_PrimitiveWire.create() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
创建导线
签名
function create(
line: Array<number> | Array<Array<number>>,
net?: string,
color?: string | null,
lineWidth?: number | null,
lineType?: ESCH_PrimitiveLineType | null,
): Promise<ISCH_PrimitiveWire | undefined>;2
3
4
5
6
7
参数名
参数 | 类型 | 描述 |
|---|---|---|
line | Array<number> | Array<Array<number>> | 多段线坐标组,每段都是连续的一组 类型 |
net | string | (可选) 网络名称,如若未指定,则遵循: 1. 没有坐标落在任何图元上,则默认为空网络; 2. 有一个坐标点在某个网络的图元上,则跟随该图元的网络; 3. 有多个坐标点在多个不同网络的图元上,则创建失败 如若已指定,则遵循: 1. 有一个或多个坐标点在其他网络的图元上,且其他图元并未显式(通常指的是包含网络标签或网络端口)指定网络,则其他图元跟随指定的网络; 2. 如若其他图元指定了网络,则创建失败 |
color | string | null | (可选) 导线颜色, |
lineWidth | number | null | (可选) 线宽,范围 |
lineType | ESCH_PrimitiveLineType | null | (可选) 线型, |
返回值
Promise<ISCH_PrimitiveWire | undefined>
导线图元对象
示例
// 1. 生成随机起点坐标,避免与画布上已有的导线重合(SCH 坐标单位 10mil)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 创建一条两段相连的 L 形导线:先向右再向上,段与段必须首尾相连且各自水平或垂直
const wire = await eda.sch_PrimitiveWire.create(
[[x, y, x + 400, y], [x + 400, y, x + 400, y + 200]],
'SIG_A', // 网络名称(自由字符串,未指定时按落点自动推断)
'#FF0000', // 导线颜色
6, // 线宽(范围 1-10)
1 // 线型:1 = DASHED(虚线)
);
// 3. 创建类保留现场,不删除图元;Line 读回是画布规格化坐标(端点顺序可能与传入相反),只打印不做断言
console.log('primitiveId:', wire.getState_PrimitiveId());
console.log('primitiveType:', wire.getState_PrimitiveType());
console.log('net:', wire.getState_Net());
console.log('color:', wire.getState_Color());
console.log('lineWidth:', wire.getState_LineWidth());
console.log('line:', JSON.stringify(wire.getState_Line()));2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20