SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

DefnitionList class

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.

Parent:Entity

Methods:[], add, add_observer, at, count, each, length, load, purge_unused, remove_observer, unique_name

Example Code: definitionlisttests.rb

Instance Methods


[]

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 for the component definition, or a string that is the name of the component definition.

Syntax

componentdefinition = definitionlist[index] 



componentdefinition = definitionlist[guid]



componentdefinition = definitionlist["componentdefinitionname"]

Arguments

index - the index for a specific component definition 

guid - the unique ID for the component definition

“componentdefinitionname” – the name of an existing component definition

Return Value

componentdefinition - a ComponentDefinition object if successful, nil if not found

Example

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

 

 


add

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

Syntax

componentdefinition = definitionlist.add "componentdefinitionname"

Arguments

componentdefinitionname - the new component definition to add to the definition list

Return Value

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

Example

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

 

 


add_observer

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

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


at

The at method is used to retrieve a component definition at a specific index.

Syntax

componentdefinition = definitionlist.at[index]

Arguments

index - the index of the component definition

Return Value

componentdefinition - the ComponentDefinition object at the specific index if successful, nil if unsuccessful

Example

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

 

 


count  

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

Syntax

count = definitionlist.length

Return Value

count - the number of component definitions in the definition list if successful

Example

model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.add "BedTraditional"
number = definitions.count   

 

 


each    

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

Syntax

definitionlist.each {| componentdefinition | ...}

Arguments

componentdefinition – a variable that will hold each ComponentDefinition object as they are found

Comments

Throws an exception if there are no component definitions.

Example

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

 

 


length

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

Syntax

length = definitionlist.length

Return Value

length - the number of component definitions in the definition list (if successful)

Example

model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.add "BedTraditional"
number = definitions.count       
if (number)
UI.messagebox number
else
UI.messagebox "Failure"
end               

 

 


load

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

Syntax

componentdefinition = definitionlist.load path

Arguments

path - the path where the component definition file is located

Return Value

componentdefinition - the loaded ComponentDefinition object if successful

Example

path=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path

 

 


purge_unused

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

Syntax

Arguments

Return Value

true if successful, false if unsuccessful.

Example

 

 


remove_observer

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

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


unique_name

The unique_name method is used to generate a unique name for a component definition.

Syntax

name = definitionlist.unique_name "startingname"

Arguments

"startingname" - the starting or base name which will be used to form the unique name

Return Value

name - the unique name if successful

Example

path=Sketchup.find_support_file "BedTraditional.skp" ,"Components/Furniture/"
model = Sketchup.active_model
definitions = model.definitions
componentdefinition = definitions.load path
name = componentdefinition.name
newname = definitions.unique_name name