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.
Example
Section titled “Example”let model = await SketchUpApi.getActiveModel();
// Get bounds of the entire modellet modelBounds = await model.getBounds();console.log('Model bounds:', modelBounds.width, modelBounds.height);// => depends on your model
// Create a face and measure it specificallyawait 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]Constructor
Section titled “Constructor”Constructor
Section titled “Constructor”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
[ |
the corner with the smallest x, y, and z values |
|
|
[ |
the corner with the largest x, y, and z values |
Returns
Section titled “Returns”BoundingBox
Example
Section titled “Example”let { BoundingBox, Point3d } = SketchUpApi;
// Start empty and grow it with add()let box = new BoundingBox();console.log(box.isEmpty);// => truebox.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 cornerslet preset = new BoundingBox([0, 0, 0], [80, 60, 0]);console.log(preset.center.toArray());// => [40, 30, 0]Accessors
Section titled “Accessors”center
Section titled “center”Get Signature
Section titled “Get Signature”get center():
Point3d
The midpoint of the box — equidistant from all six faces.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get depth():
number
The Z extent of this box in inches (the “blue axis” direction in SketchUp).
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get empty():
boolean
True when no points have been added yet (min/max are unset).
Returns
Section titled “Returns”boolean
height
Section titled “height”Get Signature
Section titled “Get Signature”get height():
number
The Y extent of this box in inches (the “green axis” direction in SketchUp).
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get max():
Point3d
The corner with the largest x, y, and z values.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get min():
Point3d
The corner with the smallest x, y, and z values.
Returns
Section titled “Returns”Get Signature
Section titled “Get Signature”get width():
number
The X extent of this box in inches (the “red axis” direction in SketchUp).
Returns
Section titled “Returns”number
Methods
Section titled “Methods”Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
‐ |
Returns
Section titled “Returns”BoundingBox
Call Signature
Section titled “Call Signature”add(
boundingBox):BoundingBox
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
|
‐ |
Returns
Section titled “Returns”BoundingBox
Call Signature
Section titled “Call Signature”add(
boundingBoxArray):BoundingBox
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
( |
‐ |
Returns
Section titled “Returns”BoundingBox
clear()
Section titled “clear()”clear():
BoundingBox
Resets this bounding box to empty. After clearing, you must add at least two points before the dimensions are non-zero.
Returns
Section titled “Returns”BoundingBox
contains()
Section titled “contains()”contains(
point_or_bb,tol?):boolean
Tests whether a point or another bounding box lies entirely within this box, within tolerance.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
|
|
|
|
‐ |
|
|
|
|
distance tolerance in inches, defaults to 0 |
Returns
Section titled “Returns”boolean