Skip to content

Active Path Support

  • SDK version 1.17.0
  • Ensure that you are connected to SketchUp
await SketchUpApi.connect();
async function getActivePath() {
const model = await SketchUpApi.getActiveModel();
const path = await model.getActivePath();
console.log('Active path:', path);
return path;
}
async function observeActivePath() {
// Get the active model
const model = await SketchUpApi.getActiveModel();
// Start observing changes to the active path
const observerHandle = model.observeActivePath(activePath => {
console.log('Active path changed:', activePath);
// You can access activePath.path and activePath.transform here
});
// To stop observing later, call:
// observerHandle.stop();
}

Modify the Active Path (with Component Hierarchy Setup)

Section titled “Modify the Active Path (with Component Hierarchy Setup)”
async function setupAndModifyActivePath() {
const model = await SketchUpApi.getActiveModel();
// Create a parent group/component
const [parent, child] = await model.performOperation(async op => {
// Create a parent group
const parent = await op.entityForRef(op.createGroup(op.model));
// Create a child group inside the parent
const child = await op.entityForRef(op.createGroup(parent));
// Optionally, add geometry to the child
op.createEdge(child, [
[0, 0, 0],
[0, 0, -100],
]);
return [parent, child];
}, 'setup component hierarchy');
// Set the active path to edit the child group inside the parent
await model.performOperation(op => {
op.modelSetActivePath([parent, child]);
}, 'set active path to [parent, child]');
}