BoundingBox

class BoundingBox

Parent: Object | Class Index
Methods:new, add, center, clear, contains?, corner, depth, diagonal, empty?, height, intersect, max, min, valid?, width |
Sample Code:boundingboxtests.rb |

Bounding boxes are three-dimensional boxes (eight corners), aligned with the global axes, that surrounds entities within your model. There is a default bounding box for any new (empty) model that will surround all entities, including all groups and components, in your model. Additionally, there are bounding boxes for all components and groups (which can be seen when selecting the component or groups). Bounding boxes are only large enough to exactly bound the entities within your model, group, or component.
The BoundingBox class is used to create and manipulate a new bounding box.

Class Methods

new
The new method is used to create a new, empty, bounding box.
Syntax:
boundingbox = Geom::BoundingBox.new
Arguments:
Return Value:
boundingbox – a BoundingBox object if successful
Comments:
Example:

boundbox = new Geom::BoundingBox.new

if (boundbox)
# creation of bounding box was successful, you can use the object
else
# creation of bounding box was not successful
end

Instance Methods

add
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.
Syntax:
boundingbox = boundingbox.add point boundingbox = boundingbox.add point1, point2, ... boundingbox = boundingbox.add boundingbox boundingbox = boundingbox.add [point1, point2, ...]
Arguments:
point1, point2, ... – A Point3d object boundingbox – a BoundingBox object
Return Value:
boundingbox – the new, resized, BoundingBox object if successful
Comments:
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.
Example:
model = Sketchup.active_model # Get the bounding box associated with the model. There will not be any size to the bounding box # until you add something prior to calling model.bounds boundingbox = model.bounds bbox = boundingbox.add_point

center
The center method is used to retrieve the Point3d object at the center of the bounding box.
Syntax:
point = boundingbox.center
Arguments:
Return Value:
point – the Point3d at the center of the bounding box if successful
Comments:
Example:
# There will not be any size to your bounding box until you add at least two points prior to calling model.bounds boundbox = model.bounds center = boundbox.center UI.messagebox center

clear
The clear method is used to clear a bounding box.
Syntax:
boundingbox = boundingbox.clear
Arguments:
Return Value:
boundingbox - the BoundingBox object which was cleared
Comments:
A cleared BoundingBox does not have a size greater than zero until you add at least two points or another bounding box.
Example:
# There will not be any size to your bounding box until you add at least two points prior to calling model.bounds boundbox = model.bounds bounding = boundbox.clear

contains?
This method is used to determine if a bounding box contains a specific Point3d or BoundingBox object.
Syntax:
status = boundingbox.contains? point | boundingbox
Arguments:
point – a Point3d object boundbox – a BoundingBox object
Return Value:
status = true if successful (bounding box contains a Point3d or BoundingBox object), or false if unsuccessful.
Comments:
Example:

point = Geom::Point3d.new(100,200,300)
model = Sketchup.active_model
bbox = boundingbox.add point
# should return true
status = bbox.contains? point

if (status)
# if true, code to do something
else
# if false, code to do something
end

corner
The corner method is used to retrieve a point object at a specified corner of the bounding box.
Syntax:
point = boundingbox.corner corner
Arguments:
corner – a number (from 0 to 7) representing point at the corner you want to retrieve.
Return Value:
point – a Point3d object if successful
Comments:
There are 8 corners to a bounding box, identified by the numbers 0 through 7. Points are returned in the currently set units (inches, by default).
Example:

# Add two points

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2

# Returns a point in the form of three coordinates, such as 6”, 0”, 0”
point = bbox.corner 1

depth
The depth method is used to retrieve the depth of the bounding box.
Syntax:
depth = boundingbox.depth
Arguments:
Return Value:
depth – the depth of the bounding box if successful
Comments:
The depth is returned in the currently set units (inches, by default).
Example:

# Add two points
point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2
# Returns the depth
depth = boundingbox.depth

diagonal
The diagonal method is used to get the length of the diagonal of the bounding box.
Syntax:
diagonal = boundingbox.diagonal
Arguments:
Return Value:
diagonal – the size of the diagonal for the bounding box if successful
Comments:
The diagonal is returned in the currently set units (inches, by default).
Example:

# Add two points
point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2
# Returns the diagonal
diagonal = boundingbox.diagonal

empty?
The empty? method is used to determine if a bounding box is empty (such as if the bounds have not been set.)
Syntax:
status = boundingbox.empty?
Arguments:
Return Value:
status – true if the bounding box is empty, false if it is not empty
Comments:
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2\
status = boundingbox.empty?
if (status)
# If true, bounding box is empty…
else
# If false, bounding box contains entities
end

height
The height method is used to retrieve the height of the bounding box.
Syntax:
height = boundingbox.height
Arguments:
Return Value:
height – the height of the bounding box
Comments:
The height is returned in the currently set units (inches, by default).
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2

# Returns the length
height = boundingbox.height

intersect
The intersect method is used to retrieve a bounding box that is the result of intersecting one bounding box with another.
Syntax:
boundingbox = boundingbox1.intersect boundingbox2
Arguments:
boundingbox2 – a second boundbox which might intersect boundingbox1
Return Value:
boundingbox – the resulting BoundingBox object if successful, an empty BoundingBox object if unsuccessful.
Comments:
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.
Example:

max
The max method is used to retrieve the Point3d object where x, y and z are maximum in the bounding box.
Syntax:
point = boundingbox.max
Arguments:
Return Value:
point – a Point3d object representing the point where x, y, and z are the maximum in the bounding box.
Comments:
If you attempt to call the max method on an empty bounding box, you will receive a very large negative number.
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2
point = boundingbox.max
UI.messagebox.point

min
The min method is used to retrieve the Point3d where x, y and z are minimum in the bounding box.
Syntax:
point = boundingbox.max
Arguments:
Return Value:
point – a Point3d object representing the point where x, y, and z are the maximum in the bounding box.
Comments:
If you attempt to call the max method on an empty bounding box, you will receive a very large positive number.
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2
point = boundingbox.min
UI.messagebox.point

valid?
The valid method is used to determine if a bounding box is valid (contains points).
Syntax:
status = boundingbox.valid?
Arguments:
Return Value:
status – true if the bounding box is valid (not empty), false if it is not valid (empty)
Comments:
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2
status = boundingbox.valid?

if (status)
# If true, bounding box is empty…
else
# If false, bounding box contains entities
end

width
The width method is used to retrieve the width of the bounding box.
Syntax:
width = boundingbox.width
Arguments:
Return Value:
width – the width of the bounding box if successful
Comments:
The diagonal is returned in the currently set units (inches, by default).
Example:

point = Geom::Point3d.new(100,200,300)
point2 = Geom::Point3d.new(300,200,100)

model = Sketchup.active_model
bbox = boundingbox.add point
bbox = boundingbox.add point2

# Returns the width
width = boundingbox.width

UI.messagebox.width