Class: Sketchup::AttributeDictionary

Inherits:
Entity show all
Includes:
Enumerable
Defined in:
lib/attributedictionary.rb

Overview

The AttributeDictionary class allows you to attach arbitrary collections of attributes to a SketchUp entity. The attributes are defined by key/value pairs where the keys are strings. An Entity or Model object can have any number of AttributeDictionary objects.

The Entity class is a popular parent class in SketchUp, meaning you can attach AttributeDictionaries to almost anything, from geometric items like edges and faces and components to more conceptual things like pages or materials.

See Also:

Since:

  • SketchUp 6.0

Instance Method Summary collapse

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #model, #parent, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#[](key) ⇒ Object

Get attribute value.

Examples:

model = Sketchup.active_model
value = model.set_attribute "test_dictionary", "test", 115
attr_dicts = model.attribute_dictionaries
attr_dicts = attr_dicts["test_dictionary"]

# value will contain 115
value = attr_dicts["test"]

Parameters:

  • key (String)

    The name of the attribute.

Returns:

  • (Object)

    The attribute stored under the given key or +nil+ if there is no attribute with the given key.

Since:

  • SketchUp 6.0


35
36
# File 'lib/attributedictionary.rb', line 35

def [](key)
end

#[]=(key, value) ⇒ Object

Set attribute value.

Examples:

model = Sketchup.active_model
value = model.set_attribute "test_dictionary", "test", 110
attr_dicts = model.attribute_dictionaries
attr_dicts = attr_dicts["test_dictionary"]
value = attr_dicts["test2"] = 120
if (value)
  UI.messagebox value
end

Parameters:

  • key (String)

    The name of the attribute.

  • value (Object)

    The value of the attribute.

Returns:

  • (Object)

    The newly assigned object if successful or +nil+ if unsuccessful.

Since:

  • SketchUp 6.0


55
56
# File 'lib/attributedictionary.rb', line 55

def []=(key, value)
end

#delete_key(key) ⇒ Object

Delete an attribute with a given key.

Examples:

create_if_nil = true
model = Sketchup.active_model
attr_dict = model.attribute_dictionary "test_dict", create_if_nil
attr_dict["attr_one"] = "one"
attr_dict["attr_two"] = "two"

# Gets an array of values
attr_dict = model.attribute_dictionaries['test_dict']
value = attr_dict.delete_key("attr_one")

Parameters:

  • key (String)

    The key to be deleted.

Returns:

  • (Object)

    The value of the key or +nil+ if the specified key doesn't exist.

Since:

  • SketchUp 6.0


75
76
# File 'lib/attributedictionary.rb', line 75

def delete_key(key)
end

#each {|key, value| ... } ⇒ nil Also known as: each_pair

Iterate through all of the attribute keys and values.

Examples:

create_if_nil = true
model = Sketchup.active_model
attr_dict = model.attribute_dictionary "test_dict", create_if_nil
attr_dict["attr_one"] = "one"
attr_dict["attr_two"] = "two"

# Iterates through all attributes and prints the key to the screen
attr_dict = model.attribute_dictionaries['test_dict']
attr_dict.each { | key, value |
  UI.messagebox key.to_s + '=' + value.to_s
}

Yield Parameters:

Returns:

  • (nil)

Since:

  • SketchUp 6.0


97
98
# File 'lib/attributedictionary.rb', line 97

def each
end

#each_key {|key| ... } ⇒ nil

Iterate through all of the attribute keys.

Examples:

create_if_nil = true
model = Sketchup.active_model
attr_dict = model.attribute_dictionary "test_dict", create_if_nil
attr_dict["attr_one"] = "one"
attr_dict["attr_two"] = "two"

# iterates through all attributes and prints the key to the screen
attr_dict = model.attribute_dictionaries['test_dict']
attr_dict.each_key { | key | UI.messagebox key }

Yield Parameters:

  • key (String)

    The key of each attribute as it is found.

Returns:

  • (nil)

Since:

  • SketchUp 6.0


116
117
# File 'lib/attributedictionary.rb', line 116

def each_key
end

#keysArray

Get an array with all of the attribute keys.

Returns:

  • (Array)

    An array of keys within the attribute dictionary.

Since:

  • SketchUp 6.0


124
125
# File 'lib/attributedictionary.rb', line 124

def keys
end

#lengthFixnum Also known as: size

Get the number of attributes in the attribute dictionary.

Examples:

model = Sketchup.active_model
model.set_attribute('Example', 'Hello', 'World')
dictionary = model.attribute_dictionary('Example')
number = dictionary.length

Returns:

  • (Fixnum)

    The size of the attribute dictionary.

Since:

  • SketchUp 6.0


136
137
# File 'lib/attributedictionary.rb', line 136

def length
end

#nameString

Get the name of an attribute dictionary.

Examples:

create_if_nil = true
model = Sketchup.active_model
attr_dict = model.attribute_dictionary "test_dict", create_if_nil
attr_dict["attr_one"] = "one"
attr_dict["attr_two"] = "two"

# Show the name.
UI.messagebox attr_dict.name

Returns:

  • (String)

    The name of the attribute dictionary.

Since:

  • SketchUp 6.0


154
155
# File 'lib/attributedictionary.rb', line 154

def name
end

#valuesArray

Get an array with all of the attribute values.

Examples:

create_if_nil = true
model = Sketchup.active_model
attr_dict = model.attribute_dictionary "test_dict", create_if_nil
attr_dict["attr_one"] = "one"
attr_dict["attr_two"] = "two"

# Gets an array of values
attr_dict = model.attribute_dictionaries['test_dict']
values = attr_dict.values

Returns:

  • (Array)

    An array of values within the attribute dictionary.

Since:

  • SketchUp 6.0


171
172
# File 'lib/attributedictionary.rb', line 171

def values
end