SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

OptionsProvider class

An OptionsProvider class provides various kinds of options on a Model. You get an OptionsProvider from the OptionsManager. The options are given as name/value pairs.  

Parent: Object 

Methods: [], []=, add_observer, count, each, each_key, each_pair, each_value, has_key?, key?, keys, name, remove_observer, size

Example Code: optionsprovidertests.rb

Instance Methods


[]

The [] method is used to get a value by name or index of the key.

Syntax

value = optionsprovider[index]
value = optionsprovider[name]

Arguments

index - the index for a specific key

name - the name of the specific key

Return Value

value - the value if successful

Example

model = Sketchup.active_model
manager = model.options
provider = manager[0]
# Retrieves each value for each key
option = provider[1]

 

 


[]= 

The []= method is used to set the value of a specific key.

Syntax

value = optionsprovider[“key"]=value

Arguments

“key” – the valid key

value – the value to be set

Return Value

value – the value that was set if successful, or false if unsuccessful.

Comments

Creates a new attribute for the given key if needed.

Example

option = provider[1]=10

 

 


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

 

 


count 

The count method is used to retrieve the size (number of elements) of an options provider.

Syntax

count = optionsprovider.count

Return Value

size – the size of the options provider if successful

Example 

count = provider.count

 

 


each 

The each method is used to iterate through all of the attributes.

Syntax

optionsprovider.each { | key, value |  … }

Arguments

key, value – variables that will hold each key and value as they are found.

Comments

Throws an exception if there are no keys.

Example

# Retrieves each key
provider.each { |key, value| UI.messagebox key }
# Retrieves each corresponding value
provider.each { |key, value| UI.messagebox key }

 

 


each_key

The each_key method is used to iterate through all of the attribute keys.

Syntax

optionsprovider.each { | key |  … }

Arguments

key– a variable that will hold each key as they are found.

Comments

Throws an exception if there are no keys.

Example

provider.each_key { |key| UI.messagebox key }

 

 


each_pair 

An alias for each. See OptionsProvider.each

Syntax

optionsprovider.each_pair {|key, value| ...} 
 

Arguments

key, value – variables that will hold each key and value as they are found.

Comments

Throws an exception if there are no keys.

Example

# Retrieves each key
provider.each_pair { |key, value| UI.messagebox key }

 

 


each_value 

The each_value method is used to iterate through all of the attribute values.

Syntax

optionsprovider.each_value { | value |  … }

Arguments

value – a variable that will hold each value as they are found.

Comments

Throws an exception if there are no keys.

Example

provider.each_value { |value| UI.messagebox value }

 

 


has_key? 

The has_key? method is used to determine if the options provider has a specific key.

Syntax

status = provider.has_key? "name"

Arguments

name - the name of the key you are looking for

Return Value

status - true if the key exists, false if the key does not exist.

Example

status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end

 

 


key? 

The key? method is used to determine if the options provider has a specific key. This method is the same as has_key? See also OptionsManager.has_key?

Syntax

status = provider.key? "name"

Arguments

name - the name of the key you are looking for

Return Value

status - true if the key exists, false if the key does not exist.

Example 

status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end

 

 


keys 

The keys method is used to retrieve an array with all of the attribute keys.

Syntax

keys = optionsprovider.keys

Return Value

keys – an array of keys within the options provider if successful

Example

keys = provider.keys
key = keys[0]
if (key)
UI.messagebox key
else
UI.messagebox "Failure"
end

 

 


name 

The name method is used to retrieve the name of an options provider.

Syntax

name = optionsprovider.name

Return Value

name – the name of the options provider if successful

Example

name = provider.name

 

 



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

 

 


size

The size method is used to retrieve the size (number of elements) of an options provider. This method is an alias for count. See also OptionsProvider.count.

Syntax

size = optionsprovider.size

Return Value

size – the size of the options provider if successful

Example

size = provider.size