My favorites | English | Sign in

Google SketchUp Ruby API

Group

class

Introduction

SketchUp 6.0+

A Group class contains methods for manipulating groups of entities.

Groups in SketchUp are very similar to Components, except that there is no instancing of groups. That means that you always will have one and only one of each of your groups. (In the actual implementation, SketchUp keeps track of groups as a special kind of Component that combines properties of definitions and instances, which is why you will see deprecated methods like Group.make_unique, and the class of observer you attach to Groups are ComponentInstance observers.)

Methods

Group.add_observerSketchUp 6.0+

The add_observer method is used to add a ComponentInstance observer to the group.

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 status = group.add_observer observer

Group.copySketchUp 6.0+

The copy method is used to create a new Group object that is a copy of the group.

Returns:

group
a new Group object
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 group2 = group.copy

Group.descriptionSketchUp 6.0+

The description method is used to retrieve the description for the group.

Returns:

description
a string description if successful
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]
 # Add the group to the entities in the model
 group = entities.add_group

 # Get the entities within the group
 entities2 = group.entities

 # Add a face to within the group
 face = entities2.add_face pts
 group.description = "This is a Group with a 2d Face"
 description = group.description

Group.description=SketchUp 6.0+

The description= method is used to set the description for the group.

Arguments:

description
A string description.

Returns:

description
the new description if successful
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]

 # Add the group to the entities in the model
 group = entities.add_group

 # Get the entities within the group
 entities2 = group.entities

 # Add a face to within the group
 face = entities2.add_face pts
 group.description = "This is a Group with a 2d Face"
 description = group.description 
 if (description)
   UI.messagebox description
 else
   UI.messagebox "Failure"
 end

Group.entitiesSketchUp 6.0+

The entities method is used to retrieve a collection of entities in the group.

Returns:

entities
an Entities object if successful
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]
 # Add the group to the entities in the model
 group = entities.add_group

 # Get the entities within the group
 entities2 = group.entities

 # Add a face to within the group
 face = entities2.add_face pts
 entities = group.entities
 if (entities)
   UI.messagebox entities
 else
   UI.messagebox "Failure"
 end

Group.explodeSketchUp 6.0+

The explode method is used to explode the group into individual entities.

Returns:

entities
an Entities object if successful
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])

 UI.messagebox "Grouped"
 status = group.explode
 if (status)
   UI.messagebox "Exploded Group"
 else
   UI.messagebox "Failure"
 end

Group.local_boundsSketchUp 7.0+

The local_bounds method returns the BoundingBox object that defines the size of the group in an untransformed state. Useful for determining the original width, height, and depth of a group regardless of its current position or scale. For components, you can get a similar result by checking my_instance.definition.bounds.

Returns:

bounds
a BoundingBox object
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 transformation = Geom::Transformation.new([100,0,0])

 # Note that local_bounds_1 and local_bounds_2 will be identical, since
 # they both find the bounding box in group's untransformed state.
 local_bounds_1 = group.local_bounds
 group.transform! transformation
 local_bounds_2 = group.local_bounds

Group.locked=SketchUp 6.0+

The locked= method is used to lock a group.

Returns:

status
true if the group is locked, false if not
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 status = group.locked = true

Group.locked?SketchUp 6.0+

The locked? method is used to determine if a group is locked.

Returns:

status
true if the group is locked, false if not.
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]

 # Add the group to the entities in the model
 group = entities.add_group
 status = group.locked?
 UI.messagebox status

Group.make_uniqueSketchUp 6.0+

The make_unique method is a deprecated method used to force a group to have a unique definition.

Copying a group using the copy tool in SketchUp will create copies of the group that share a common definition until an instance is edited manually or this method is used. If multiple copies are made, all copies share a definition until all copies are edited manually, or all copies have this method used on them. This method ensures that the group uses a unique definition entry in the drawing database.

Returns:

group
the unique group
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 group.make_unique

Group.move!SketchUp 6.0+

The move! method is used to apply a transformation to the group.

This method is the same as the transform! method except that it does not record the move in an undo operation. This method is useful for transparently moving things during an animation.

Arguments:

transform
A Transformation object.

Returns:

group
the transformed Group object if successful
 point = Geom::Point3d.new 500,500,500
 t = Geom::Transformation.new point
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]

 # Add the group to the entities in the model
 group = entities.add_group

 # Get the entities within the group
 entities2 = group.entities

 # Add a face to within the group
 face = entities2.add_face pts
 UI.messagebox "Group before Move"
 group = group.move! t
 if (group)
   UI.messagebox "Group after move"
   UI.messagebox group
 else
   UI.messagebox "Failure"
 end

Group.nameSketchUp 6.0+

The name method is used to retrieve the name of the group.

Returns:

name
The name of the group if successful
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 group.name = "A Line"
 name = group.name

Group.name=SketchUp 6.0+

The name= method is used to set the description for the group.

Arguments:

name
A string name.

Returns:

name
a new name if successful
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])
 group.name = "A Line"
 name = group.name

Group.remove_observerSketchUp 6.0+

The remove_observer method is used to remove a ComponentInstance observer from the group.

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 group = Sketchup.active_model.entities[0]
 if group != nil
   if group.typename == "Group"
     status = group.remove_observer observer
   end
 end

Group.to_componentSketchUp 6.0+

The to_component method is used to convert the group to a component instance.

Arguments:

none
Undefined.

Returns:

instance
the new ComponentInstance object
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])

 # change the group to a component instance
 group.to_component

Group.transform!SketchUp 6.0+

The transform! method is used to apply a transformation to a group.

Arguments:

transform
A Transformation object.

Returns:

group
a transformed group object if successful
 point = Geom::Point3d.new 500,500,500
 t = Geom::Transformation.new point
 depth = 100
 width = 100
 model = Sketchup.active_model
 entities = model.active_entities
 pts = []
 pts[0] = [0, 0, 0]
 pts[1] = [width, 0, 0]
 pts[2] = [width, depth, 0]
 pts[3] = [0, depth, 0]

 # Add the group to the entities in the model
 group = entities.add_group

 # Get the entities within the group
 entities2 = group.entities

 # Add a face to within the group
 face = entities2.add_face pts
 UI.messagebox "Group before Move"
 group = group.transform! t
 if (group)
   UI.messagebox "Group after move"
   UI.messagebox group
 else
   UI.messagebox "Failure"
 end

Group.transformationSketchUp 6.0+

The transformation method is used to retrieve the transformation for the group.

Returns:

transformation
a Transformation object if successful
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])

 trans = group.transformation

Group.transformation=SketchUp 6.0+

The transformation= method is used to set the transformation for the group.

Arguments:

transform
The Transformation object to apply

Returns:

group
the newly trasformed group
 # Add a group to the model.
 group = Sketchup.active_model.entities.add_group
 group.entities.add_line([0,0,0],[100,100,100])

 new_transform = Geom::Transformation.new([100,0,0])
 group.transformation = new_transform