DefinitionList

SketchUp 6.0+

class

Parent: Entity

Introduction

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.

Methods

DefinitionList.[]SketchUp 6.0+

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.

Arguments:

key
The index for a specific component definition, the unique GUID for the component definition, or the name of an existing component definition.

Returns:

componentdefinition
a ComponentDefinition object if successful, nil if not found
 path=Sketchup.find_support_file "Bed.skp",
   "Components/Components Sampler/"
 model = Sketchup.active_model
 definitions = model.definitions
 componentdefinition = definitions.load path
 component = definitions[0]

DefinitionList.addSketchUp 6.0+

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

Arguments:

def_name
The new component definition to add to the definition list.

Returns:

componentdefinition
the ComponentDefinition object that was added (if successful)
 model = Sketchup.active_model
 definitions = model.definitions
 componentdefinition = definitions.add "BedTraditional"
 component = definitions[0]

DefinitionList.add_observerSketchUp 6.0+

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

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 definitions = Sketchup.active_model.definitions
 status = definitions.add_observer observer

DefinitionList.atSketchUp 6.0+

The at method is used to retrieve a component definition at a specific index. This is an alias for the [] method.

Arguments:

key
The index for a specific component definition, the unique GUID for the component definition, or the name of an existing component definition.

Returns:

componentdefinition
the ComponentDefinition object at the specific index if successful, nil if unsuccessful
 model = Sketchup.active_model
 definitions = model.definitions
 componentdefinition = definitions.add "BedTraditional"
 component = definitions.at 0

DefinitionList.countSketchUp 6.0+

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.

Returns:

integer
the number of component definitions in the definition list if successful
 model = Sketchup.active_model
 definitions = model.definitions
 number = definitions.count

DefinitionList.eachSketchUp 6.0+

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.

Arguments:

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

Returns:

nil
 model = Sketchup.active_model
 definitions = model.definitions
 componentdefinition = definitions.add "BedTraditional"
 number = definitions.each {|definition| UI.messagebox definition.to_s }

DefinitionList.lengthSketchUp 6.0+

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

Returns:

integer
the number of component definitions in the definition list if successful
 model = Sketchup.active_model
 definitions = model.definitions
 number = definitions.length

DefinitionList.loadSketchUp 6.0+

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

Arguments:

path
The path where the component definition file is located.

Returns:

componentdefinition
the loaded ComponentDefinition object if successful
 path=Sketchup.find_support_file "Bed.skp",
   "Components/Components Sampler/"
 model = Sketchup.active_model
 definitions = model.definitions
 componentdefinition = definitions.load path

DefinitionList.load_from_urlSketchUp 7.0+

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)
  • Arguments:

    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:

    true if successful
     class LoadHandler
    
       def onPercentChange(p)
         Sketchup::set_status_text("LOADING:    " + p.to_i.to_s + "%")
       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)
         # A real implementation would probably not use a global variable,
         # but this demonstrates storing any error we receive.
         $last_error = error_message
         Sketchup::set_status_text('')
       end
    
     end
    
     # Replace this with a real URL...
     url = 'http://www.sketchup.com/model.skp'
     load_handler = LoadHandler.new
     Sketchup.active_model.definitions.load_from_url url, load_handler
    
     if load_handler.error == nil
       last_def_id = Sketchup.active_model.definitions.count - 1
       loaded_definition = Sketchup.active_model.definitions[last_def_id]
     else
       UI.messagebox("Error: " + $last_error.to_s)
     end

DefinitionList.purge_unusedSketchUp 6.0+

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

Returns:

true if successful, false if unsuccessful.
 # Need ruby code example here.

DefinitionList.remove_observerSketchUp 6.0+

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

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 definitions = Sketchup.active_model.definitions
 status = definitions.remove_observer observer

DefinitionList.sizeSketchUp 2014+

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

Returns:

integer
the number of component definitions in the definition list if successful
 model = Sketchup.active_model
 definitions = model.definitions
 number = definitions.size

DefinitionList.unique_nameSketchUp 6.0+

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"

Arguments:

base_name
The

Returns:

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

  

Trimble Home
About Trimble - Privacy Policy - Contact Us