My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

BoundingBox

class

Parent: Object

Introduction

SketchUp 6.0+

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

Methods

BoundingBox.addSketchUp 6.0+

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:

points_or_bb
A list or single instance or Point3d or BoundingBox objects

Returns:

boundingbox
the new, resized, BoundingBox object if successful
 model = Sketchup.active_model
 bbox = model.bounds
 point1 = Geom::Point3d.new(100, 200, 300)
 bbox = bbox.add point1

BoundingBox.centerSketchUp 6.0+

The center method is used to retrieve the Point3d object at the center of the bounding box.

Returns:

point
the Point3d at the center of the bounding box if successful
 # 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

BoundingBox.clearSketchUp 6.0+

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:

boundingbox
the BoundingBox object which was cleared
 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)

BoundingBox.contains?SketchUp 6.0+

This method is used to determine if a bounding box contains a specific Point3d or BoundingBox object.

Arguments:

point
A Point3d object.
boundbox
A BoundingBox object.

Returns:

status
true if successful (bounding box contains a Point3d or BoundingBox object), or false if unsuccessful.
 point = Geom::Point3d.new(100,200,300)
 bbox = Sketchup.active_model.bounds
 bbox.add point
 # should return true
 status = bbox.contains? point

BoundingBox.cornerSketchUp 6.0+

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

  1. . Points are returned in the currently set units (inches, by default). These
are which index refers to which corner:

  • 0 = [0, 0, 0] (left front bottom)
  • 1 = [1, 0, 0] (right front bottom)
  • 2 = [0, 1, 0] (left back bottom)
  • 3 = [1, 1, 0] (right back bottom)
  • 4 = [0, 0, 1] (left front top)
  • 5 = [1, 0, 1] (right front top)
  • 6 = [0, 1, 1] (left back top)
  • 7 = [1, 1, 1] (right back top)
  • Arguments:

    corner
    A number (from 0 to 7) representing point at the corner you want to retrieve.

    Returns:

    point
    a Point3d object if successful
     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)

BoundingBox.depthSketchUp 6.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:

depth
the depth of the bounding box if successful
 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)

BoundingBox.diagonalSketchUp 6.0+

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:

diagonal
the size of the diagonal for the bounding box if successful
 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)

BoundingBox.empty?SketchUp 6.0+

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:

status
true if the bounding box is empty, false if it is not empty
 bbox = Sketchup.active_model.bounds
 status = bbox.empty?
 if (status)
   # If true, bounding box is empty.
 else
   # If false, bounding box contains entities.
 end

BoundingBox.heightSketchUp 6.0+

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:

height
the height of the bounding box
 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)

BoundingBox.intersectSketchUp 6.0+

The intersect method is used to retrieve a bounding box that is the result of intersecting one bounding box with another.

Arguments:

boundingbox2
A second boundbox which might intersect boundingbox1.

Returns:

boundingbox
the resulting BoundingBox object if successful, an empty BoundingBox object if unsuccessful.
 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

BoundingBox.maxSketchUp 6.0+

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:

point
a Point3d object representing the point where x, y, and z are the maximum in the bounding box.
 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)

BoundingBox.minSketchUp 6.0+

The min method is used to retrieve the Point3d where x, y and z are minimum in the bounding box.

Returns:

point
a Point3d object representing the point where x, y, and z are the maximum in the bounding box.
 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)

BoundingBox.newSketchUp 6.0+

The new method is used to create a new, empty, bounding box.

Returns:

boundingbox
a BoundingBox object if successful
 boundbox = Geom::BoundingBox.new

BoundingBox.valid?SketchUp 6.0+

The valid method is used to determine if a bounding box is valid (contains points).

Returns:

status
true if the bounding box is valid (not empty), false if it is not valid (empty)
 bbox = Sketchup.active_model.bounds
 status = bbox.valid?
 if (status)
   # If true, bounding box is empty.
 else
   # If false, bounding box contains entities.
 end

BoundingBox.widthSketchUp 6.0+

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:

width
the width of the bounding box
 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)