Bounding boxes are three-dimensional boxes (eight corners), aligned with the
global axes, that surround entities within your model. There is a default
bounding box for any new model that will surround all entities,
including all groups and components. Additionally, there are
bounding boxes for Drawingelement objects, including components and groups.
Bounding boxes are only large enough to exactly bound the entities within
your model, group, or component.
You can also create arbitrary BoundingBox objects by calling BoundingBox.new.
# You can get the bounding box on a model.
model = Sketchup.active_model
model_bb = model.bounds
# Or you can get the bounding box on any Drawingelement object.
first_entity = model.entities[0]
first_entity_bb = first_entity.bounds
# Or you can create an empty bounding box of your own.
boundbox = Geom::BoundingBox.new
The add method is used to add a point, or other bounding boxes, to the
bounding box. The size of the bounding box will increase as necessary to
accommodate the new points or bounding boxes.
Adding one point to an empty bounding box, does not increase the size of the
bounding box. You must add at least two points before methods, such as
BoundingBox.diagonal, will return a size greater than zero.
Arguments:
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) bbox = bbox.add point1
The center method is used to retrieve the Point3d object at the center of the bounding box.
Returns:
# There will not be any size to your bounding box until you add at least # two points prior to calling model.bounds boundbox = Sketchup.active_model.bounds center = boundbox.center UI.messagebox center
The clear method is used to clear a bounding box.
A cleared BoundingBox does not have a size greater than zero until you add
at least two points or another bounding box.
Returns:
bbox = Geom::BoundingBox.new
bbox.add [0,0,0]
bbox.add [100,100,100]
UI.messagebox("before clear, bounding box empty? " + bbox.empty.to_s)
bbox.clear
UI.messagebox("after clear, bounding box empty? " + bbox.empty.to_s)This method is used to determine if a bounding box contains a specific Point3d or BoundingBox object.
Arguments:
Returns:
point = Geom::Point3d.new(100,200,300) bbox = Sketchup.active_model.bounds bbox.add point # should return true status = bbox.contains? point
The corner method is used to retrieve a point object at a specified corner
of the bounding box.
There are 8 corners to a bounding box, identified by the numbers 0 through
Arguments:
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 UI.messagebox(bbox.corner 0)
The depth method is used to retrieve the depth of the bounding box.
The depth is returned in the currently set units (inches, by default).
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 UI.messagebox(bbox.depth)
The diagonal method is used to get the length of the diagonal of the
bounding box.
The diagonal is returned in the currently set units (inches, by default).
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 UI.messagebox(bbox.diagonal)
The empty? method is used to determine if a bounding box is empty (such as if the bounds have not been set.) This returns the opposite of the valid? method.
Returns:
bbox = Sketchup.active_model.bounds status = bbox.empty? if (status) # If true, bounding box is empty. else # If false, bounding box contains entities. end
The height method is used to retrieve the height of the bounding box.
The height is returned in the currently set units (inches, by default).
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 UI.messagebox(bbox.height)
The intersect method is used to retrieve a bounding box that is the result of intersecting one bounding box with another.
Arguments:
Returns:
boundingbox1 = Geom::BoundingBox.new boundingbox1.add [0,0,0] boundingbox1.add [100,100,100] boundingbox2 = Geom::BoundingBox.new boundingbox2.add [50,50,50] boundingbox2.add [150,150,150] boundingbox = boundingbox1.intersect boundingbox2
The max method is used to retrieve the Point3d object where x, y and z are
maximum in the bounding box.
If you attempt to call the max method on an empty bounding box, you will
receive a very large negative number.
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 point = bbox.max UI.messagebox(point.to_s)
The min method is used to retrieve the Point3d where x, y and z are minimum in the bounding box.
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 point = bbox.min UI.messagebox(point.to_s)
The new method is used to create a new, empty, bounding box.
Returns:
boundbox = Geom::BoundingBox.new
The valid method is used to determine if a bounding box is valid (contains points).
Returns:
bbox = Sketchup.active_model.bounds status = bbox.valid? if (status) # If true, bounding box is empty. else # If false, bounding box contains entities. end
The width method is used to retrieve the width of the bounding box.
The width is returned in the currently set units (inches, by default).
Returns:
model = Sketchup.active_model bbox = model.bounds point1 = Geom::Point3d.new(100, 200, 300) point2 = Geom::Point3d.new(300, 200, 100) bbox = bbox.add point1 bbox = bbox.add point2 UI.messagebox(bbox.width)