SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Group class

A Group class contains methods for manipulating groups of entities.

Parent:Drawingelement

Methods: add_observer, copy, description, description=, entities, explode, locked?, locked=, make_unique, move!, name, name=, remove_observer, to_component, transform!, transformation, transformation= 

Example Code: grouptests.rb

Instance Methods


add_observer

The add_observer method is used to add an observer to the current object.

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


copy 

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

Syntax

group = group.copy 

Return Value

group - a new Group object

Example

group2 = group.copy

 

 


description 

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

Syntax

description = group.description 

Return Value

description - a string description if successful

Example

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

 

 


description= 

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

Syntax

description = group.description = "description" 
 

Arguments

"description" - a string description

Return Value

description - the new description if successful

Example

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

 

 


entities 

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

Syntax

entities = group.entities 

Return Value

entities - an Entities object if successful

Example

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

 

 


explode 

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

Syntax

entities = group.explode 

Return Value

entities - an Entities object if successful

Example

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

 

 


locked? 

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

Syntax

status = group.locked?

Return Value

status - true if the component instance is locked. False if the instance is not locked.

Example

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

 

 


locked= 

The locked= method is used to lock a group.

Syntax

status = group.locked=true|false

Arguments 

true | false - true if you want to lock the group; false if you want to unlock the group.

Return Value

status - true if the is locked. False if the group is not locked.

 

 


move! 

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

Syntax

group = group.move! transformation 

Arguments

transformation - a Transformation object

Return Value

group - the transformed Group object if successful

Comments

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.

Example

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
  

 

 


name 

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

Syntax

name = group.name 

Return Value

name - The name of the group if successful

Example

group.name = "2d Face"
name = group.name

 

 


name= 

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

Syntax

name = group.name = "name" 
 

Arguments

"name" - a string name

Return Value

name - a new name if successful

Example

group.name = "2d Face"
name = group.nam

 

 



remove_observer

The remove_observer method is used to remove an observer from the current object.

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


to_component 

The to_component method is used to.

Syntax

 

Arguments

 

Return Value

 

Example

 

 


transform! 

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

Syntax

group = group.transform! transformation 
 

Arguments

transformation - a Transformation object

Return Value

group - a transformed group object if successful

Example

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
           

 

 


transformation   

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

Syntax

transformation = group.transformation 
 

Return Value

transformation - a Transformation object if successful

Example

trans = group.transformation

 

 


transformation= 

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

Syntax

transformation = group.transformation = transformation 

Arguments

transformation - the Transformation object applied to the group

Return Value

transformation - the Transformation object if successful

Example

trans = group.transformation=t