Class: Sketchup::DefinitionList

Inherits:
Entity
  • Object
show all
Includes:
Enumerable

Overview

A DefinitionList object holds a list of all of the ComponentDefinition objects in a model. This class contains methods for adding and retrieving definitions from the list.

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Methods inherited from Entity

#attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #parent, #persistent_id, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#[](index) ⇒ Sketchup::ComponentDefinition? #[](name) ⇒ Sketchup::ComponentDefinition? #[](guid) ⇒ Sketchup::ComponentDefinition?

The [] method is used to retrieve a component definition from the list. You can give an integer index in the range 0 to length, a string which represents the GUID (a unique internal identifier), or a string that is the name of the definition.

Examples:

path=Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
component = definitions[0]

Overloads:

Version:

  • SketchUp 6.0

#add(def_name) ⇒ Object

The add method is used to add a new component definition to the definition list with the given name.

Examples:

model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.add "BedTraditional"
component = definitions[0]

Returns componentdefinition - the ComponentDefinition object that was added (if successful)

Parameters:

  • def_name

    The new component definition to add to the definition list.

Returns:

  • componentdefinition - the ComponentDefinition object that was added (if successful)

Version:

  • SketchUp 6.0

#add_observer(observer) ⇒ Object

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

Examples:

definitions = Sketchup.active_model.definitions
status = definitions.add_observer observer

Returns true if successful, false if unsuccessful.

Parameters:

  • observer

    An observer.

Returns:

  • true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#[](index) ⇒ Sketchup::ComponentDefinition? #[](name) ⇒ Sketchup::ComponentDefinition? #[](guid) ⇒ Sketchup::ComponentDefinition?

The [] method is used to retrieve a component definition from the list. You can give an integer index in the range 0 to length, a string which represents the GUID (a unique internal identifier), or a string that is the name of the definition.

Examples:

path=Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
component = definitions[0]

Overloads:

Version:

  • SketchUp 6.0

#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:

model = Sketchup.active_model
definitions = model.definitions
number = definitions.count

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 6.0

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

The each method is used to iterate through all of the component definitions in the definition list.

Throws an exception if there are no component definitions.

Examples:

model = Sketchup.active_model
definitions = model.definitions
definitions.add("BedTraditional")
number = definitions.each { |definition| puts definition.name }

Yields:

  • (definition)

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

Returns:

  • nil

Version:

  • SketchUp 6.0

#lengthInteger

The #length method is used to retrieve number of component definitions in the list.

The #size method is an alias for #length added in SketchUp 2014.

Examples:

model = Sketchup.active_model
definitions = model.definitions
number = definitions.length

Returns:

  • (Integer)

    the number of component definitions in the definition list if successful

Version:

  • SketchUp 6.0

#load(path) ⇒ Object

The load method is used to load a component from a file.

Examples:

path=Sketchup.find_support_file "Bed.skp",
  "Components/Components Sampler/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path

Returns componentdefinition - the loaded ComponentDefinition object if successful

Parameters:

  • path

    The path where the component definition file is located.

Returns:

  • componentdefinition - the loaded ComponentDefinition object if successful

Version:

  • SketchUp 6.0

#load_from_url(url, load_handler) ⇒ Object

The load_from_url method loads a component from a location specified by string url. This method throws an exception if an url string is not given, or an error occurs during retrieval from url and a load_handler was not given. Optional second parameter load_handler can be used to pass in a ruby object that responds to the following methods:

- cancelled?(a_boolean)
- onPercentChange(a_float)
- onSuccess()
- onFailure(message_string)

Examples:

class LoadHandler

  attr :error

  def onPercentChange(percent)
    Sketchup::set_status_text("LOADING: #{percent}%")
  end

  def cancelled?
    # You could, for example, show a messagebox after X seconds asking if the
    # user wants to cancel the download. If this method returns true, then
    # the download cancels.
    return false
  end

  def onSuccess
    Sketchup::set_status_text('')
  end

  def onFailure(error_message)
    self.error = error_message
    Sketchup::set_status_text('')
  end

end

# Replace this with a real URL...
url = 'http://www.sketchup.com/model.skp'
model = Sketchup.active_model
definition = model.definitions.load_from_url(url, load_handler)

if definition.nil?
  puts "Error: #{load_handler.error}"
end

Returns componentdefinition - the loaded ComponentDefinition object if successful

Parameters:

  • url

    URL to load a .skp file from.

  • load_handler (optional)

    Ruby object that has methods defined as described in the load_from_url details.

Returns:

  • componentdefinition - the loaded ComponentDefinition object if successful

Version:

  • SketchUp 7.0

#purge_unusedObject

The purge_unused method is used to remove the unused component definitions.

Examples:

definitions = Sketchup.active_model.definitions
definitions.purge_unused

Returns:

  • Sketchup::DefinitionList object

Version:

  • SketchUp 6.0

#remove_observer(observer) ⇒ Object

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

Examples:

definitions = Sketchup.active_model.definitions
status = definitions.remove_observer observer

Returns true if successful, false if unsuccessful.

Parameters:

  • observer

    An observer.

Returns:

  • true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#sizeInteger

The #length method is used to retrieve number of component definitions in the list.

The #size method is an alias for #length added in SketchUp 2014.

Examples:

model = Sketchup.active_model
definitions = model.definitions
number = definitions.length

Returns:

  • (Integer)

    the number of component definitions in the definition list if successful

Version:

  • SketchUp 6.0

#unique_name(base_name) ⇒ Object

The unique_name is used to generate a unique name for a definition based on a base_name string. For example, a base_name of “Joe” might return “Joe #2”

Examples:

model = Sketchup.active_model
definitions = model.definitions
new_name = definitions.unique_name "My Base Name"

Returns new_name - the unique name.

Parameters:

  • base_name

Returns:

  • new_name - the unique name.

Version:

  • SketchUp 6.0