Class: Sketchup::Selection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb

Overview

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.

Examples:

# Get a handle to the selection set.
model = Sketchup.active_model
selection = model.selection

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Sketchup::Entitiy?

The #[] method is used to retrieve an Entity 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 #each instead of using this method to manually grab each one.

Examples:

model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
selection.add(entities.to_a)
p selection[0]

See Also:

Version:

  • SketchUp 6.0



46
47
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 46

def [](index)
end

#add(entities) ⇒ Integer #add(*entities) ⇒ Integer

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.

Examples:

# Add by listing the entities...
ss.add(e1, e2, e3)

# ...or add by passing an Array of entities.
ss.add([e1, e2, e3])
entities = model.active_entities
entity = entities[0]
status = selection.add entity

Version:

  • SketchUp 6.0



81
82
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 81

def add(*args)
end

#add_observer(observer) ⇒ Boolean

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

Examples:

selection = Sketchup.active_model.selection
status = selection.add_observer observer

Version:

  • SketchUp 6.0



96
97
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 96

def add_observer(observer)
end

#at(index) ⇒ Sketchup::Entitiy?

The #at method is an alias for #[].

Examples:

model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
selection.add(entities.to_a)
p selection.at(0)

See Also:

Version:

  • SketchUp 6.0



116
117
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 116

def at(index)
end

#clearnil

The clear method is used to clear the selection.

Examples:

entity = entities[0]
selection.add entity
UI.messagebox "Ready to Clear"
selection.clear

Version:

  • SketchUp 6.0



130
131
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 130

def clear
end

#contains?(entity) ⇒ Boolean

The #contains? method is and alias of #include?.

Examples:

model = Sketchup.active_model
entity = model.active_entities.first
selection = model.selection
selection.add(entity)
p selection.contains?(entity)

See Also:

Version:

  • SketchUp 6.0



149
150
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 149

def contains?(entity)
end

#countInteger

Note:

Since SketchUp 2014 the count method is inherited from Ruby’s Enumable mix-in module. Prior to that the #count method is an alias for #length.

Examples:

selection = Sketchup.active_model.selection
number = selection.count

See Also:

Version:

  • SketchUp 6.0



166
167
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 166

def count
end

#each {|Sketchup::Entity| ... } ⇒ nil

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 [].

Examples:

selection.each { |entity| UI.messagebox(entity) }

Yields:

  • (Sketchup::Entity)

    A variable that will hold each Entity object as they are found.

Version:

  • SketchUp 6.0



183
184
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 183

def each
end

#empty?Boolean

The empty? method is used to determine if there are entities in the selection.

Examples:

status = selection.add entity
status = selection.empty

Version:

  • SketchUp 6.0



196
197
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 196

def empty?
end

#firstSketchup::Entity

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.

Examples:

status = selection.add entity
entity = selection.first

Version:

  • SketchUp 6.0



212
213
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 212

def first
end

#include?(entity) ⇒ Boolean

The #include? method is used to determine if a given Entity is in the selection.

Examples:

model = Sketchup.active_model
entity = model.active_entities.first
selection = model.selection
selection.add(entity)
p selection.include?(entity)

See Also:

Version:

  • SketchUp 6.0



232
233
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 232

def include?(entity)
end

#invertnil

The ##invert method is used to invert the selection.

Examples:

model = Sketchup.active_model
entities = model.active_entities
selection = model.selection
# Create a cube
face = entities.add_face([0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0])
face.pushpull(-9)
# Add the first two faces to the selection
faces = entities.grep(Sketchup::Face).take(2)
selection.add(faces)
# Invert selection
selection.invert

Version:

  • SketchUp 2019.2



253
254
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 253

def invert
end

#is_curve?Boolean

The is_curve? method is used to determine if the selection contains all edges that belong to a single curve.

Examples:

selection.add entity
status = selection.is_curve?

Version:

  • SketchUp 6.0



266
267
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 266

def is_curve?
end

#is_surface?Boolean

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.

Examples:

selection.add entity
status = selection.is_surface

Version:

  • SketchUp 6.0



279
280
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 279

def is_surface?
end

#lengthInteger

The #length method is used to retrieve the number of selected entities.

Examples:

selection = Sketchup.active_model.selection
number = selection.length

See Also:

Version:

  • SketchUp 6.0



295
296
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 295

def length
end

#modelSketchup::Model

The model method retrieves the model for the selection.

Examples:

model = selection.model

Version:

  • SketchUp 6.0



307
308
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 307

def model
end

#nitemsInteger

The #nitems method is an alias for #length.

Examples:

selection = Sketchup.active_model.selection
number = selection.nitems

See Also:

Version:

  • SketchUp 6.0



321
322
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 321

def nitems
end

#remove(entities) ⇒ Integer #remove(*entities) ⇒ Integer

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.

Examples:

# Remove by listing the entities...
ss.remove(e1, e2, e3)

# ...or remove by passing an Array of entities.
ss.remove([e1, e2, e3])
entities = model.active_entities
entity = entities[0]
status = selection.add entity

Version:

  • SketchUp 6.0



355
356
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 355

def remove(*args)
end

#remove_observer(observer) ⇒ Boolean

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

Examples:

selection = Sketchup.active_model.selection
status = object.remove_observer observer

Version:

  • SketchUp 6.0



371
372
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 371

def remove_observer(observer)
end

#shiftSketchup::Entity

The shift method is used to remove the first entity from the selection and returns it.

Examples:

status = selection.add entity
UI.messagebox "Ready to remove item from selection set"
entity = selection.shift

Version:

  • SketchUp 6.0



386
387
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 386

def shift
end

#single_object?Boolean

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.

Examples:

status = selection.single_object

Version:

  • SketchUp 6.0



401
402
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 401

def single_object?
end

#sizeInteger

The #size method is an alias for #length.

Examples:

selection = Sketchup.active_model.selection
number = selection.size

See Also:

Version:

  • SketchUp 2014



415
416
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 415

def size
end

#toggle(entities) ⇒ Integer #toggle(*entities) ⇒ Integer

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.

Examples:

# Toggle by listing the entities...
ss.toggle(e1, e2, e3)

# ...or toggle by passing an Array of entities.
ss.toggle([e1, e2, e3])
entities = model.active_entities
entity = entities[0]
status = selection.add entity

Version:

  • SketchUp 6.0



451
452
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Selection.rb', line 451

def toggle(*args)
end