Skip to content

Transforms

let model = await SketchUpApi.getActiveModel();
let selection = await model.getSelection();
model.performOperation((op) => {
// Transform using the translate shorthand (an array with 3 numbers)
// This will transform all x coords by 0, y coords by 0 and z coords by 100
op.drawingElementsApplyTransformation(selection.drawingElements, [0, 0, 100]);
}, 'translate selected elements');

You may find that applying transformations one at a time can result in undesirable intersections of geometry. To avoid this you can apply multiple different transforms atomically using this method

let model = await SketchUpApi.getActiveModel();
let selection = await model.getSelection();
model.performOperation((op) => {
// Transform using the translate shorthand (an array with 3 numbers)
// This will transform all x coords by 0, y coords by 0 and z coordinates randomly between 0 and 100.
const transforms = selection.drawingElements.map((drawingElement) => {
return [0, 0, Math.random() * 100];
})
op.drawingElementsBulkTransformation(selection.drawingElements, transforms);
}, 'translate selected elements');