Home > SCH_PrimitiveRectangle > create
SCH_PrimitiveRectangle.create() method
Create Rectangle
Signature
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>;2
3
4
5
6
7
8
9
10
11
12
13
Parameters
Parameter | Type | Description |
|---|---|---|
topLeftX | number | Top-left point X |
topLeftY | number | Top-left point Y |
width | number | Width |
height | number | Height |
cornerRadius | number | (Optional) Corner radius |
rotation | number | (Optional) Rotation angle, rotating around the top-left point. Options: |
color | string | null | (Optional) Color, |
fillColor | string | null | (Optional) Fill color. |
lineWidth | number | null | (Optional) Line width, range |
lineType | ESCH_PrimitiveLineType | null | (Optional) Line type. |
fillStyle | ESCH_PrimitiveFillStyle | null | (Optional) Fill style, |
Returns
Promise<ISCH_PrimitiveRectangle | undefined>
Rectangle primitive object
Example
// 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());2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19