Home > SCH_PrimitiveRectangle > create
SCH_PrimitiveRectangle.create() method
创建矩形
签名
typescript
function create(
topLeftX: number,
topLeftY: number,
width: number,
height: number,
cornerRadius?: number,
rotation?: number,
color?: string | null,
fillColor?: string | null,
lineWidth?: number | null,
lineType?: ESCH_PrimitiveLineType | null,
fillStyle?: ESCH_PrimitiveFillStyle | null,
): Promise<ISCH_PrimitiveRectangle | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
参数名
参数 | 类型 | 描述 |
|---|---|---|
topLeftX | number | 左上点 X |
topLeftY | number | 左上点 Y |
width | number | 宽 |
height | number | 高 |
cornerRadius | number | (可选) 圆角半径 |
rotation | number | (可选) 旋转角度,绕左上点旋转,可选 |
color | string | null | (可选) 颜色, |
fillColor | string | null | (可选) 填充颜色, |
lineWidth | number | null | (可选) 线宽,范围 |
lineType | ESCH_PrimitiveLineType | null | (可选) 线型, |
fillStyle | ESCH_PrimitiveFillStyle | null | (可选) 填充样式, |
返回值
Promise<ISCH_PrimitiveRectangle | undefined>
矩形图元对象
示例
javascript
// 1. 生成随机左上角坐标,避免与画布上已有的矩形重合(SCH 坐标单位 10mil)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
// 2. 创建一个宽 400 高 300 的圆角矩形:圆角 20、旋转 90 度(绕左上点)、红色虚线边线、黄色网格填充、线宽 6
const rect = await eda.sch_PrimitiveRectangle.create(x, y, 400, 300, 20, 90, '#FF0000', '#FFFF00', 6, 1, 'Grid');
// 3. 创建类保留现场,不删除图元
console.log('primitiveId:', rect.getState_PrimitiveId());
console.log('primitiveType:', rect.getState_PrimitiveType());
console.log('topLeft:', rect.getState_TopLeftX(), rect.getState_TopLeftY());
console.log('size:', rect.getState_Width(), 'x', rect.getState_Height());
console.log('cornerRadius:', rect.getState_CornerRadius());
console.log('rotation:', rect.getState_Rotation());
console.log('color:', rect.getState_Color());
console.log('fillColor:', rect.getState_FillColor());
console.log('fillStyle:', rect.getState_FillStyle());
console.log('lineWidth:', rect.getState_LineWidth());
console.log('lineType:', rect.getState_LineType());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19