Skip to main content

GetType

Returns the type of the current selection.

Syntax

expression.GetType();

expression - A variable that represents a ApiSelection class.

Parameters

This method doesn't have any parameters.

Returns

SelectionType

Example

Identify the type of selection in different scenarios in a presentation.

// How do I determine what is selected in a presentation?

// Check the selection type before and after adding a shape in a presentation.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();
const selection = Api.GetSelection();

let type = selection.GetType();
let text = 'Type: ' + type + ' (no selection scenario)\n';

const fill = Api.CreateSolidFill(Api.RGB(0, 0, 0));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('rect', 200 * 36000, 10 * 36000, fill, stroke);
slide.AddObject(shape);
shape.Select();

type = selection.GetType();
text += 'Type: ' + type + ' (shape added scenario)\n';

const outShapeFill = Api.CreateSolidFill(Api.RGB(50, 70, 180));
const outShapeStroke = Api.CreateStroke(0, Api.CreateNoFill());
const outShape = Api.CreateShape('rect', 200 * 36000, 30 * 36000, outShapeFill, outShapeStroke);
outShape.SetPosition(0, 20 * 36000);

const outDoc = outShape.GetDocContent();
const outParagraph = outDoc.GetElement(0);
outParagraph.AddText(text);
slide.AddObject(outShape);