|
SketchUp Ruby API Reference |
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
The [] method is used to get a value by name or index of the key.
value = optionsprovider[index]
value = optionsprovider[name]
index - the index for a specific key
name - the name of the specific key
value - the value if successful
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.
value = optionsprovider[“key"]=value
“key” – the valid key
value – the value to be set
value – the value that was set if successful, or false if unsuccessful.
Creates a new attribute for the given key if needed.
option = provider[1]=10
The add_observer method is used to add an observer to the current object.
status = object.add_observer observer
observer - an observer
true if successful, false if unsuccessful.
The count method is used to retrieve the size (number of elements) of an options provider.
count = optionsprovider.count
size – the size of the options provider if successful
count = provider.count
The each method is used to iterate through all of the attributes.
optionsprovider.each { | key, value | … }
key, value – variables that will hold each key and value as they are found.
Throws an exception if there are no keys.
# Retrieves each keyprovider.each { |key, value| UI.messagebox key }# Retrieves each corresponding valueprovider.each { |key, value| UI.messagebox key }
The each_key method is used to iterate through all of the attribute keys.
optionsprovider.each { | key | … }
key– a variable that will hold each key as they are found.
Throws an exception if there are no keys.
provider.each_key { |key| UI.messagebox key }
An alias for each. See OptionsProvider.each
optionsprovider.each_pair {|key, value| ...}
key, value – variables that will hold each key and value as they are found.
Throws an exception if there are no keys.
# Retrieves each keyprovider.each_pair { |key, value| UI.messagebox key }
The each_value method is used to iterate through all of the attribute values.
optionsprovider.each_value { | value | … }
value – a variable that will hold each value as they are found.
Throws an exception if there are no keys.
provider.each_value { |value| UI.messagebox value }
The has_key? method is used to determine if the options provider has a specific key.
status = provider.has_key? "name"
name - the name of the key you are looking for
status - true if the key exists, false if the key does not exist.
status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end
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?
status = provider.key? "name"
name - the name of the key you are looking for
status - true if the key exists, false if the key does not exist.
status = provider.has_key? "PageOptions"
if (status)
UI.messagebox status
else
UI.messagebox "Failure"
end
The keys method is used to retrieve an array with all of the attribute keys.
keys = optionsprovider.keys
keys – an array of keys within the options provider if successful
keys = provider.keyskey = keys[0]if (key)UI.messagebox keyelseUI.messagebox "Failure"end
The name method is used to retrieve the name of an options provider.
name = optionsprovider.name
name – the name of the options provider if successful
name = provider.name
The remove_observer method is used to remove an observer from the current object.
status = object.remove_observer observer
observer - an observer
true if successful, false if unsuccessful.
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.
size = optionsprovider.size
size – the size of the options provider if successful
size = provider.size
|
SketchUp Ruby API Reference: OptionsProvider |
© Google Inc. 2007 sketchup.google.com |