CreateShape
Creates a shape with the parameters specified.
Syntax
expression.CreateShape(shapeType, width, height, fill, stroke);
expression - A variable that represents an Api class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| shapeType | Optional | ShapeType | "rect" | The shape type which specifies the preset shape geometry. The "textRect" type creates a text box as the editor inserts it: a light fill and a thin black outline. |
| width | Optional | EMU | 914400 | The shape width in English measure units. |
| height | Optional | EMU | 914400 | The shape height in English measure units. |
| fill | Optional | ApiFill | The color or pattern used to fill the shape. If not specified, the default shape style fill (theme accent) is used. | |
| stroke | Optional | ApiStroke | The stroke used to draw the shape outline. If not specified, the default shape style outline (theme accent) is used. |
Returns
ApiShape | null | undefined
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);