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) ⇒ Sketchup::ComponentDefinition

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]

Parameters:

  • def_name (String)

    The new component definition to add to the definition list.

Returns:

Version:

  • SketchUp 6.0

#add_observer(observer) ⇒ Boolean

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

Parameters:

  • observer (Object)

    An observer.

Returns:

  • (Boolean)

    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 {|Sketchup::ComponentDefinition| ... } ⇒ nil

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:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#lengthInteger

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

Examples:

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

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 6.0

#load(path) ⇒ Sketchup::ComponentDefinition

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

Parameters:

  • path (String)

    The path where the component definition file is located.

Returns:

Raises:

  • RuntimeError If filename is an invalid SketchUp model. Added in SketchUp 2019. Possible that prior versions of SketchUp will crash.

Version:

  • SketchUp 6.0

#load_from_url(url, load_handler = nil) ⇒ Sketchup::ComponentDefinition

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

Parameters:

  • url (String)

    URL to load a .skp file from.

  • load_handler (Object) (defaults to: nil)

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

Returns:

Version:

  • SketchUp 7.0

#purge_unusedSketchup::DefinitionList

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

Examples:

definitions = Sketchup.active_model.definitions
definitions.purge_unused

Returns:

Version:

  • SketchUp 6.0

#remove(definition) ⇒ Boolean

The #remove method is used to remove a component definition from the definition list with the given component definition. This will remove all instances of the definition.

Examples:

model = Sketchup.active_model
definitions = model.definitions
definition = definitions[0]
definitions.remove(definition)

Parameters:

Returns:

  • (Boolean)

Version:

  • SketchUp 2018

#remove_observer(observer) ⇒ Boolean

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

Parameters:

  • observer (Object)

    An observer.

Returns:

  • (Boolean)

    true if successful, false if unsuccessful.

Version:

  • SketchUp 6.0

#sizeInteger

The #size method is an alias for #length.

Examples:

model = Sketchup.active_model
definitions = model.definitions
number = definitions.size

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 2014

#unique_name(base_name) ⇒ String

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 鈥淛oe鈥 might return 鈥淛oe #2鈥

Examples:

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

Parameters:

Returns:

  • (String)

    the unique name.

Version:

  • SketchUp 6.0