Skip to content

Tools

Access to SketchUp’s active tool — read it, watch for changes, and trigger component placement.

Get this object from model.tools. Use it to detect which tool the user has active, react when they switch tools, or programmatically activate the component placement tool.

let model = await SketchUpApi.getActiveModel();
// Watch for tool activations
let handle = model.tools.observeToolChanges(
change => {
if (change.event === 'Activation') {
console.log(change.tool.name);
// => 'PaintTool', 'RectangleTool', etc.
}
}
);
// Stop observing when done
handle.stop();

SDK 1.19.0 protocol 1.16.0

clearActiveTool(): Promise<Tool>

Deactivates any active tool and returns the user to Select mode.

Promise<Tool>

SDK 1.19.0 protocol 1.16.0


getActive(): Promise<Tool>

Returns the currently active tool, if any.

Promise<Tool>

SDK 1.19.0 protocol 1.16.0


observeToolChanges(callback): ObserverHandle

Calls callback on every tool lifecycle event — initial state, activation, and state changes. Returns a handle to stop observing.

Parameter Type Description

callback

(change) => void

invoked with each ToolEvent

ObserverHandle

SDK 2.30.0 protocol 1.16.0


placeComponentOnce(component): Promise<ComponentInstance | undefined>

Activates the place-component tool and waits for the user to click to place it, then resolves with the placed ComponentInstance. Resolves with undefined if the user cancels. If the user deletes the component definition before placing, the snapshot is invalidated.

Parameter Type Description

component

ComponentDefinition | ComponentDefinitionRef

the component definition to place

Promise<ComponentInstance | undefined>

the placed instance, or undefined if cancelled


placeComponentRepeatedly(component, callback?): Promise<ComponentInstance[]>

Activates the place-component tool in multi-place mode, letting the user stamp multiple instances. Each time the user places an instance the optional callback is called. Resolves with the full array of placed instances when the user cancels or switches to another tool.

Parameter Type Description

component

ComponentDefinition | ComponentDefinitionRef

the component definition to place

callback

(instances) => void

invoked after each placement with the new instances

Promise<ComponentInstance[]>


toString(): string

string

streamToolChanges(callback): ObserverHandle

Streams changes to the current active tool

Parameter Type Description

callback

(change) => void

invoked on every tool change

ObserverHandle

SDK 1.19.0 protocol 1.16.0