跳到主要内容

SetGeometry

为当前形状设置自定义几何形状。

语法

expression.SetGeometry(oGeometry);

expression - 表示 ApiShape 类的变量。

参数

名称必需/可选数据类型默认值描述
oGeometry必需ApiGeometry自定义几何形状。

返回值

boolean

示例

在文档中用自定义绘制的路径替换形状的轮廓。

// How do I give a shape a custom geometric outline in a document?

// Define a unique silhouette for a shape by providing hand-drawn path coordinates in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let customGeometry = Api.CreateCustomGeometry();
let path = customGeometry.AddPath();
path.SetWidth(100 * 36000);
path.SetHeight(100 * 36000);
path.SetStroke(true);
path.SetFill("norm");
path.MoveTo(50 * 36000, 0);
path.LineTo(70 * 36000, 45 * 36000);
path.LineTo(55 * 36000, 70 * 36000);
path.LineTo(100 * 36000, 100 * 36000);
path.LineTo(0, 100 * 36000);
path.Close();
let fill = Api.CreateSolidFill(Api.RGB(255, 200, 100));
let stroke = Api.CreateStroke(36000, Api.CreateSolidFill(Api.RGB(200, 100, 0)));
let shape = Api.CreateShape("rect", 100 * 36000, 100 * 36000, fill, stroke);
shape.SetGeometry(customGeometry);
paragraph.AddDrawing(shape);