跳到主要内容

CreateShape

使用指定的参数创建形状。

语法

expression.CreateShape(shapeType, width, height, fill, stroke);

expression - 表示 Api 类的变量。

参数

名称必需/可选数据类型默认值描述
shapeType可选ShapeType"rect"指定预设形状几何图形的形状类型。
width可选EMU914400以英制度量单位表示的形状宽度。
height可选EMU914400以英制度量单位表示的形状高度。
fill可选ApiFillApi.CreateNoFill()用于填充形状的颜色或图案。
stroke可选ApiStrokeApi.CreateStroke(0, Api.CreateNoFill())用于创建元素阴影的笔触。

返回值

ApiShape

示例

此示例使用 'rect' 预设创建形状。

// Creates the "rect" shape and adds it to the first paraghraph of the document.

// How to create the ApiShape object and add it to the ApiParagraph class.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let gs1 = Api.CreateGradientStop(Api.RGB(255, 213, 191), 0);
let gs2 = Api.CreateGradientStop(Api.RGB(255, 111, 61), 100000);
let fill = Api.CreateLinearGradientFill([gs1, gs2], 5400000);
let stroke = Api.CreateStroke(0, Api.CreateNoFill());
let shape = Api.CreateShape("rect", 5930900, 395605, fill, stroke);
paragraph.AddDrawing(shape);