|
SketchUp Ruby API Reference |
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
The add_observer method is used to add an observer to the current object.
status = object.add_observer observer
observer - an observer
true if successful, false if unsuccessful.
The copy method is used to create a new Group object that is a copy of the group.
group = group.copy
group - a new Group object
group2 = group.copy
The description method is used to retrieve the description for the group.
description = group.description
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 if (description)
UI.messagebox description
else
UI.messagebox "Failure"
end
The description= method is used to set the description for the group.
description = group.description = "description"
"description" - a string description
description - the new description if successful
depth = 100width = 100model = Sketchup.active_modelentities = model.active_entitiespts = []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 modelgroup = entities.add_group# Get the entities within the groupentities2 = group.entities# Add a face to within the groupface = entities2.add_face ptsgroup.description = "This is a Group with a 2d Face"description = group.description
if (description)
UI.messagebox description
else
UI.messagebox "Failure"
end
The entities method is used to retrieve a collection of entities in the group.
entities = group.entities
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
The explode method is used to explode the group into individual entities.
entities = group.explode
entities - an Entities object if successful
UI.messagebox "Grouped"
status = group.explode
if (status)
UI.messagebox "Exploded Group"
else
UI.messagebox "Failure"
end
The locked? method is used to determine if a group is locked.
status = group.locked?
status - true if the component instance is locked. False if the instance is not locked.
depth = 100width = 100model = Sketchup.active_modelentities = model.active_entitiespts = []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 modelgroup = entities.add_groupstatus = group.locked?UI.messagebox status
The locked= method is used to lock a group.
status = group.locked=true|false
true | false - true if you want to lock the group; false if you want to unlock the group.
status - true if the is locked. False if the group is not locked.
The move! method is used to apply a transformation to the group.
group = group.move! transformation
transformation - a Transformation object
group - the transformed Group object if successful
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.
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
The name method is used to retrieve the name of the group.
name = group.name
name - The name of the group if successful
group.name = "2d Face"
name = group.name
The name= method is used to set the description for the group.
name = group.name = "name"
"name" - a string name
name - a new name if successful
group.name = "2d Face"
name = group.nam
The remove_observer method is used to remove an observer from the current object.
status = object.remove_observer observer
observer - an observer
true if successful, false if unsuccessful.
The to_component method is used to.
The transform! method is used to apply a transformation to a group.
group = group.transform! transformation
transformation - a Transformation object
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
The transformation method is used to retrieve the transformation for the group.
transformation = group.transformation
transformation - a Transformation object if successful
trans = group.transformation
The transformation= method is used to set the transformation for the group.
transformation = group.transformation = transformation
transformation - the Transformation object applied to the group
transformation - the Transformation object if successful
trans = group.transformation=t
|
SketchUp Ruby API Reference: Group |
© Google Inc. 2007 sketchup.google.com |