|
SketchUp Ruby API Reference |
The AttributeDictionaries class is a container class for a collection of AttributeDictionary objects.
Parent: Object
Example Code: attrdicttests.rb
The [] method is used to retrieve the AttributeDictonary object with a provided name.
attributedictionary = attributedictionaries["attributedictionaryname"]
“attributedictionaryname” – the name of an existing attribute dictionary
attributedictionary – an attribute dictionary object if successful, nil if unsuccessful
This method also throws an exception when a dictionary of the provided name is not found.
model = Sketchup.active_model
attrdicts = model.attribute_dictionaries
begin
attrdict = attrdicts[“testdictionary”]
rescue
UI.messagebox $!.message
end
if (attrdict)
# code if an attribute dictionary is returned
end
The delete method is used to delete an attribute dictionary
status = attrributedictionaries(attributedictionary “attributedictionaryname”)
attributedictionary or “attributedictionaryname” – an attribute dictionary object or the name of an attribute dictionary to delete
status – a reference to an attribute dictionary if successful
Throws an exception if unsuccessful or returns nil.
model = Sketchup.active_modelattrdicts = model.attribute_dictionariesattrdict = attrdicts[“testdictionary”]
beginstatus = attrdicts.delete(attrdict)rescueUI.messagebox $!.messageendif (status)# code if an attribute dictionary is returnedend
The each method is used to iterate through all of the AttributeDictionary objects in the AttributeDictionaries object.
attributedictionaries.each { | attributedictionary | … }
attributedictionary – a variable that will hold each attribute dictionary object as they are found if successful
Throws an exception if there are no attribute dictionaries.
dictionaries = model.attribute_dictionaries
# iterates through all attribute dictionaries and prints the size (number of attributes) to the screen
dictionaries.each { | attributedictionary | UI.messagebox attributedictionary.size }