Skip to content

Selection

A snapshot of the drawing elements currently selected in SketchUp.

Retrieve the selection with model.getSelection(). It captures what the user has selected at a point in time — clicking, dragging, or triple-clicking in the viewport updates the selection. Because it’s a snapshot, call refresh() if the user changes their selection after you fetched it, or use model.observeSelectionMetadata() to be notified automatically whenever the selection changes.

Use model.getSelectionMetadata() if you only need counts and flags (like isCurve or isSingleObject) without downloading the full list of entities.

let model = await SketchUpApi.getActiveModel();
let sel = await model.getSelection();
console.log(sel.drawingElements.length);
// => number of selected entities
console.log(sel.isSingleObject);
// => true if exactly one thing is selected
// Later, after the user makes changes...
let updated = await sel.refresh();

SDK 2.14.0 Protocol 1.11.0

readonly drawingElements: readonly DrawingElement[]

The selected entities, respecting the filter that was passed to getSelection() (if any). Empty array if nothing matches.


readonly isCurve: boolean

True if the selection forms a continuous chain of connected edges, like a polyline or circle. Useful for curve-editing operations.


readonly isSingleObject: boolean

True if exactly one entity is selected — handy for single-object workflows like editing properties or applying materials.


readonly isSurface: boolean

True if all selected entities belong to a single continuous surface (one or more coplanar faces). Useful for surface-editing operations.


readonly totalNumberOfElements: number

Total number of selected entities in SketchUp, ignoring any filter. Use this to detect if the filter excluded some selected items.

refresh(): Promise<Selection>

Re-fetches the selection from SketchUp to pick up any changes the user made since this snapshot was taken. The filter originally passed to getSelection() is preserved — if you filtered for faces only, the refresh will also return only faces.

Promise<Selection>

let model = await SketchUpApi.getActiveModel();
let sel = await model.getSelection();
console.log(sel.drawingElements.length);
// Later, after the user makes changes...
let updated = await sel.refresh();
console.log(updated.drawingElements.length);