Skip to content

BoundingBox

An axis-aligned box that encloses a set of geometry.

Every drawing element in SketchUp has a bounding box that describes the smallest axis-aligned rectangular volume containing it. You can use bounding boxes to quickly check whether entities overlap, compute overall model extents, or position new geometry relative to existing objects.

Retrieve a bounding box from any entity with model.getBounds(entity.sketchupId), or construct one manually and grow it by calling add() with points or other bounding boxes.

let model = await SketchUpApi.getActiveModel();
// Get bounds of the entire model
let modelBounds = await model.getBounds();
console.log('Model bounds:',
modelBounds.width, modelBounds.height
);
// => depends on your model
// Create a face and measure it specifically
await model.performOperation(async op => {
op.createFace(model, [
[0, 0, 0], [80, 0, 0],
[80, 60, 0], [0, 60, 0]
]);
}, 'Create rectangle');
let faces = await model.entities.get(
{ filterBy: { types: ['Face'] } }
);
let bounds = await model.getEntityBoundsById(
faces[0].sketchupId
);
console.log('width:', bounds.width);
console.log('height:', bounds.height);
console.log('center:', bounds.center.toArray());
// => width: 80
// => height: 60
// => center: [40, 30, 0]

new BoundingBox(min?, max?): BoundingBox

Creates a bounding box. Called with no arguments, it starts empty (isEmpty is true) — use add() to grow it from there. Passing min/max corners builds it pre-populated.

Parameter Type Description

min?

[number, number, number] | Point3d

the corner with the smallest x, y, and z values

max?

[number, number, number] | Point3d

the corner with the largest x, y, and z values

BoundingBox

let { BoundingBox, Point3d } = SketchUpApi;
// Start empty and grow it with add()
let box = new BoundingBox();
console.log(box.isEmpty);
// => true
box.add(new Point3d(0, 0, 0));
box.add(new Point3d(80, 60, 0));
console.log(box.width, box.height);
// => 80 60
// Or construct pre-populated from corners
let preset = new BoundingBox([0, 0, 0], [80, 60, 0]);
console.log(preset.center.toArray());
// => [40, 30, 0]

get center(): Point3d

The midpoint of the box — equidistant from all six faces.

Point3d


get depth(): number

The Z extent of this box in inches (the “blue axis” direction in SketchUp).

number


get empty(): boolean

True when no points have been added yet (min/max are unset).

boolean


get height(): number

The Y extent of this box in inches (the “green axis” direction in SketchUp).

number


get max(): Point3d

The corner with the largest x, y, and z values.

Point3d


get min(): Point3d

The corner with the smallest x, y, and z values.

Point3d


get width(): number

The X extent of this box in inches (the “red axis” direction in SketchUp).

number

add(point): BoundingBox

Grows this bounding box to enclose the given point, bounding box, or array of points/boxes. You need to add at least two distinct points before width, height, or depth will return a value greater than zero.

Parameter Type Description

point

Point3d

‐

BoundingBox

add(boundingBox): BoundingBox

Parameter Type Description

boundingBox

BoundingBox

‐

BoundingBox

add(boundingBoxArray): BoundingBox

Parameter Type Description

boundingBoxArray

(Point3d | BoundingBox)[]

‐

BoundingBox


clear(): BoundingBox

Resets this bounding box to empty. After clearing, you must add at least two points before the dimensions are non-zero.

BoundingBox


contains(point_or_bb, tol?): boolean

Tests whether a point or another bounding box lies entirely within this box, within tolerance.

Parameter Type Default value Description

point_or_bb

Point3d | BoundingBox

undefined

‐

tol

number

0

distance tolerance in inches, defaults to 0

boolean