Skip to content

Selection

let model = await SketchUpApi.getActiveModel();
let selection = await model.getSelection();
// print number of elements
console.log(selection.totalNumberOfElements);
console.log(selection.drawingElements);
let model = await SketchUpApi.getActiveModel();
// Only grab the faces
let selection = await model.getSelection({filter:'typeIn', values: [SketchUpApi.EntityType.Face]});
// print number of elements in selection (ignoring the filter)
console.log(selection.totalNumberOfElements);
// prints only the faces
console.log(selection.drawingElements);
let model = await SketchUpApi.getActiveModel();
let selection = await model.getSelectionMetadata();
// print number of elements (matchingDrawingElements) is the same as totalNumberOfElements when no filter is supplied
console.log(selection.totalNumberOfElements);
console.log(selection.matchingDrawingElements);
let model = await SketchUpApi.getActiveModel();
// Only grab the faces
let selection = await model.getSelectionMetadata({filter:'typeIn', values: [SketchUpApi.EntityType.Face]});
// print number of elements in selection (ignoring the filter)
console.log(selection.totalNumberOfElements);
// prints only the faces
console.log(selection.matchingDrawingElements);
let model = await SketchUpApi.getActiveModel();
let handle = model.observeSelectionMetadata((metadata) => {
console.log(`The user has selected ${metadata.totalNumberOfElements} entities`);
});
// make sure to close the handle when you no longer need the stream
setTimeout(() => handle.stop(), 60 * 1000)

Filtered streaming of the current selection metadata

Section titled “Filtered streaming of the current selection metadata”
let model = await SketchUpApi.getActiveModel();
let handle = model.observeSelectionMetadata((metadata) => {
console.log(`The user has selected ${metadata.matchingDrawingElements} faces`);
}, {filter: 'typeIn', values: [SketchUpApi.EntityType.Face]});
// make sure to close the handle when you no longer need the stream
setTimeout(() => handle.stop(), 60 * 1000)
async function selectEntities(elements, model) {
await model.updateSelection(elements, 'replace');
}
async function appendEntities(elements, model) {
await model.updateSelection(elements, 'add');
}
async function removeEntities(elements, model) {
await model.updateSelection(elements, 'remove');
}
async function toggleEntities(elements, model) {
await model.updateSelection(elements, 'toggle');
}
let model = await SketchUpApi.getActiveModel();
await model.invertSelection();