A set of the currently selected entities. Use the Model.selection method to get a Selection object. Note that the order of entities (selection[0], selection[1] and so on) in the set is in no particular order and should not be assumed to be in the same order as the user selected the entities.
# Get a handle to the selection set.
model = Sketchup.active_model
selection = model.selection
The [] method is used to retrieve an Entity object from the selection by
index. Index 0 is the first entity in the selection.
This method is not very efficient. If you need to look at every entity in
the selection, consider using Selection.each instead of using this method
to manually grab each one.
Arguments:
Returns:
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 face to the entities in the model face = entities.add_face pts selection = model.selection entity = entities[0] status = selection.add entity entity = selection[0] if (entity) UI.messagebox entity else UI.messagebox "Failure" end
The add method is used to add entities to the selection. Entities that are
added to the Selection are visually indicated by the selection bounding box.
You can pass it individual Entities or an Array of Entities:
Note that the add, remove, and toggle methods are all aliases for one another. So if you call remove on an entity that is not selected, it will be toggled to be selected, not removed! Be cautious when writing your code to not make the assumption about the currently selected state of a given entity.
Arguments:
Returns:
entities = model.active_entities entity = entities[0] status = selection.add entity
The add_observer method is used to add an observer to the selection object.
Arguments:
Returns:
selection = Sketchup.active_model.selection status = selection.add_observer observer
The at method is used to retrieve an Entity object from the selection by
index.
This method is not very efficient. It is equivalent to using selection[]. In
the case of this method, you have to start at index 0 to retrieve the first
entity.
Arguments:
Returns:
entity = entities[0] status = selection.add entity # looks like you have to retrieve from the selection set starting # at zero. entity = selection.at(0)
The clear method is used to clear the selection.
Returns:
entity = entities[0] selection.add entity UI.messagebox "Ready to Clear" selection.clear
The contains? method is used to determine if a given entity is in the selection.
Arguments:
Returns:
entity = entities[0] status = selection.add entity status = selection.contains? entity if (status) UI.messagebox status else UI.messagebox "Failure" end
The count method is an alias for length. See also length.
Returns:
number = selection.count
The each method is used to iterate through all of the selected entities.
If you want to do something with all of the selected Entities, this is more
efficient than using [].
Arguments:
Returns:
selection.each { |entity| UI.messagebox(entity) }The empty? method is used to determine if there are entities in the selection.
Returns:
status = selection.add entity status = selection.empty
The first method is used to retrieve the first selected entity
Returns nil if nothing is selected. This method is useful when you know that
only a single entity is selected, or you are only interested in the first
selected entity.
Returns:
status = selection.add entity entity = selection.first
The include? method is an alias for contains
Arguments:
Returns:
selection.add entity status = selection.include? entity
The is_curve? method is used to determine if the selection contains all edges that belong to a single curve.
Returns:
selection.add entity status = selection.is_curve?
The is_surface? method is used to determine if the selection contains only all of the faces that are part of a single curved surface.
Returns:
selection.add entity status = selection.is_surface
The length method is used to retrieve the number of selected Entities.
Returns:
number = selection.length
The model method retrieves the model for the selection.
Returns:
model = selection.model
The nitems method is an alias for length. See also length.
Returns:
number = selection.nitems
The remove method is used to remove entities from the selection.
You can pass it individual Entities or an Array of Entities:
Note that the add, remove, and toggle methods are all aliases for one another. So if you call remove on an entity that is not selected, it will be toggled to be selected, not removed! Be cautious when writing your code to not make the assumption about the currently selected state of a given entity.
Arguments:
Returns:
entities = model.active_entities entity = entities[0] status = selection.add entity
The remove_observer method is used to remove an observer from the selection object.
Arguments:
Returns:
selection = Sketchup.active_model.selection status = object.remove_observer observer
The shift method is used to remove the first entity from the selection and returns it.
Returns:
status = selection.add entity UI.messagebox "Ready to remove item from selection set" entity = selection.shift
The single_object? method is used to determine if the selection contains a
single object.
It can either be a single Entity or a group of Entities for which is_curve?
or is_surface? will return true.
Returns:
status = selection.single_object
The toggle method is used to change whether an entity is part of the
selection. Entities that are not already selected
are added. Entities that are already selected are removed.
You can pass it individual Entities or an Array of Entities:
Note that the add, remove, and toggle methods are all aliases for one another. So if you call remove on an entity that is not selected, it will be toggled to be selected, not removed! Be cautious when writing your code to not make the assumption about the currently selected state of a given entity.
Arguments:
Returns:
entities = model.active_entities entity = entities[0] status = selection.add entity