Class: Sketchup::Set

Inherits:
Object
  • Object
show all

Overview

The set class represents a collection of unique objects. This class is useful for keeping track of a group of related entities, kind of like a selection set that stays around for as long as you need it to.

To make a set of your own, create an empty one using Sketchup::Set.new, and then add items to it. Note that in SketchUp 2014 this class was changed from Set to Sketchup::Set in order to avoid conflict with the Ruby Standard Library. The Sketchup::Set class is deprecated and new extensions should make use of Ruby's Set class unless they need backward compatibility.

If you want to ensure backwards compatibility you can use this shim:

Examples:

my_set = Sketchup::Set.new
my_set.insert entity1
my_set.insert entity2
module Example

  # Shim for the Set class which was moved in SketchUp 2014
  if defined?(Sketchup::Set)
    Set = Sketchup::Set
  end

  def self.test_set_shim
    s = Set.new
    s.insert('Hello')
    s.insert('World')
    puts s.to_a
  end

end

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#clearObject

The clear method is used to clear all objects out of the set.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
if (set.include? toolbar)
  UI.messagebox "Success: Contains Toolbar Object"
else
  UI.messagebox "Failure"
end
set.clear
if (set.include? toolbar)
  UI.messagebox set
else
  UI.messagebox "Set is empty"
end

Returns:

  • set - an empty Set object

Version:

  • SketchUp 6.0

#contains?(object) ⇒ Object

The contains? method is an alias for include?. See also Set.include?

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
if (set.contains? toolbar)
  UI.messagebox "Success: Contains Toolbar Object"
else
  UI.messagebox "Failure"
end

Returns status - true if the set contains the object, false if the set does not contain the object.

Parameters:

  • object

    A Ruby object of any type.

Returns:

  • status - true if the set contains the object, false if the set does not contain the object.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#delete(object) ⇒ Object

The delete object is used to delete or remove an object from the set.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
if (set.include? toolbar)
  UI.messagebox "Success: Contains Toolbar Object"
else
  UI.messagebox "Failure"
end
set.delete toolbar
if (set.include? toolbar)
  UI.messagebox set
else
  UI.messagebox "Set is empty"
end

Returns object - the object that was deleted.

Parameters:

  • object

    The object to be deleted.

Returns:

  • object - the object that was deleted.

Version:

  • SketchUp 6.0

#each {|item| ... } ⇒ Object

The each method is used to iterate through all of the objects in the set.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
set.each { | item | UI.messagebox item }

Yields:

  • (item)

Version:

  • SketchUp 6.0

#empty?Object

The empty? method is used to determine whether the set is empty.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
status = set.empty?
if (status)
  UI.messagebox "Success: Set is Empty"
else
  UI.messagebox "Failure: Set has an Item"
end

Returns:

  • status - true if the set is empty, false if it is not empty.

  • (Boolean)

Version:

  • SketchUp 6.0

#contains?(object) ⇒ Object

The contains? method is an alias for include?. See also Set.include?

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
if (set.contains? toolbar)
  UI.messagebox "Success: Contains Toolbar Object"
else
  UI.messagebox "Failure"
end

Returns status - true if the set contains the object, false if the set does not contain the object.

Parameters:

  • object

    A Ruby object of any type.

Returns:

  • status - true if the set contains the object, false if the set does not contain the object.

Returns:

  • (Boolean)

Version:

  • SketchUp 6.0

#insert(object) ⇒ Object

The insert method is used to insert an object into the set.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
if (set.include? toolbar)
  UI.messagebox "Success: Contains Toolbar Object"
else
  UI.messagebox "Failure"
end

Returns size - the number of objects in the set

Parameters:

  • object

    The object to be inserted into the set.

Returns:

  • size - the number of objects in the set

Version:

  • SketchUp 6.0

#lengthObject

The length method is an alias for size. See also Set.size.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
length = set.length
if (length)
  UI.messagebox length
else
  UI.messagebox "Failure"
end

Returns:

  • length - the length (number of objects) in the set

Version:

  • SketchUp 6.0

#sizeObject

The length method is an alias for size. See also Set.size.

Examples:

set = Sketchup::Set.new
toolbar = UI::Toolbar.new "Test"
set.insert toolbar
length = set.length
if (length)
  UI.messagebox length
else
  UI.messagebox "Failure"
end

Returns:

  • length - the length (number of objects) in the set

Version:

  • SketchUp 6.0

#to_aObject

The to_a method is used to get an Array of the entities in your Set.

Examples:

set = Sketchup::Set.new
set.insert('Hello')
set.insert('World')
my_array = set.to_a
UI.messagebox my_array

Returns:

  • array - The Array of the entities in the Set.

Version:

  • SketchUp 6.0