Skip to main content

CreateShape

Creates a shape with the parameters specified.

Syntax​

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

expression - A variable that represents a Api class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
shapeTypeOptionalShapeType"rect"The shape type which specifies the preset shape geometry.
widthOptionalEMU914400The shape width in English measure units.
heightOptionalEMU914400The shape height in English measure units.
fillOptionalApiFillApi.CreateNoFill()The color or pattern used to fill the shape.
strokeOptionalApiStrokeApi.CreateStroke(0, Api.CreateNoFill())The stroke used to create the element shadow.

Returns​

ApiShape

Example​

Insert a rectangle shape into a paragraph in a document.

// How do I add a shape to a paragraph in a document?

// Place a colored gradient-filled rectangle inside existing text content in a document.

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);