跳到主要内容

GetCommandCount

返回当前路径的命令数量。

语法

expression.GetCommandCount();

expression - 表示 ApiPath 类的变量。

参数

此方法没有任何参数。

返回值

number

示例

计算演示文稿中形状几何路径中的绘图命令数。

// How do I find out how many drawing commands are in a shape in a presentation?

// Retrieve the total number of path commands used to draw a shape in a presentation.

let presentation = Api.GetPresentation();
let slide = presentation.GetSlideByIndex(0);
let fill = Api.CreateSolidFill(Api.RGB(100, 150, 200));
let stroke = Api.CreateStroke(36000, Api.CreateSolidFill(Api.RGB(50, 75, 100)));
let shape = Api.CreateShape("star5", 100 * 36000, 100 * 36000, fill, stroke);
let geometry = shape.GetGeometry();
let path = geometry.GetPath(0);
let commands = path.GetCommands();
let cmd = path.GetCommand(0);
let paragraph = shape.GetDocContent().GetElement(0);
paragraph.AddText("Commands: " + path.GetCommandCount());
paragraph.AddText(", First: " + cmd.GetType() + " at (" + cmd.GetX() + ", " + cmd.GetY() + ")");
shape.SetPosition(1000000, 1000000);
slide.AddObject(shape);