123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::AttributeDictionaries

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Entity
Instance Chain:
self, Enumerable, Entity
Inherits: Sketchup::Entity

Overview

The AttributeDictionaries class is a collection of all of the AttributeDictionary objects that are attached to a given Entity object.

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.

You access this class not by performing an AttributeDictionaries.new but by grabbing a handle from an existing entity.

Examples:

# Grab the first entity from the model.
my_layer = Sketchup.active_model.entities[0]

# Grab a handle to its attribute dictionaries.
attrdicts = my_layer.attribute_dictionaries

Version:

  • SketchUp 6.0

Instance Attribute Summary

Entity - Inherited

#deleted?

The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example.).

#valid?

The #valid? method is used to determine if your entity is still valid (not deleted by another script, for example).

Instance Method Summary

Entity - Inherited

#add_observer

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

#attribute_dictionaries

The attribute_dictionaries method is used to retrieve the AttributeDictionaries collection attached to the entity.

#attribute_dictionary

The attribute_dictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.

#delete_attribute

The #delete_attribute method is used to delete an attribute from an entity.

#entityID

The entityID method is used to retrieve a unique ID assigned to an entity.

#get_attribute

The #get_attribute method is used to retrieve the value of an attribute in the entity’s attribute dictionary.

#inspect

The #inspect method is used to retrieve the string representation of the entity.

#model

The model method is used to retrieve the model for the entity.

#parent

The parent method is used to retrieve the parent of the entity.

#persistent_id

The #persistent_id method is used to retrieve a unique persistent id assigned to an entity.

#remove_observer

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

#set_attribute

The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.

#to_s

The #to_s method is used to retrieve the string representation of the entity.

#typename

The typename method retrieves the type of the entity, which will be a string such as “Face”, “Edge”, or “Group”.

Instance Method Details

#[](key) ⇒ Sketchup::AttributeDictionary

Get an AttributeDictionary by name. Returns nil if there is none with the given name.

Examples:

model = Sketchup.active_model
attrdicts = model.attribute_dictionaries
# Iterates through all dictionaries and prints to screen.
dict = attrdicts['my_dictionary']
if dict
  UI.messagebox("Found: " + dict.to_s)
else
  UI.messagebox("No dictionary found.")
end

Parameters:

  • key (String)

    The name of the attribute dictionary.

Returns:

Version:

  • SketchUp 6.0

#countInteger

The count method is inherited from the Enumerable mix-in module.

Examples:

model = Sketchup.active_model
model.set_attribute('Example', 'Hello', 'World')
dictionaries = model.attribute_dictionaries
number = dictionaries.count

See Also:

Version:

  • SketchUp 2014

#delete(key_or_dict) ⇒ AttributeDictionaries

The delete method destroys a given AttributeDictionary. This AttributeDictionary can be passed directly or identified by its string name.

In SketchUp 2018, special attribute dictionaries have been added. The name of these dictionaries are “SU_InstanceSet” and “SU_DefinitionSet”. The dictionaries cannot be deleted via ruby and an ArgumentError will be raised. The key/value pairs in the dictionary can be deleted safely.

object

Examples:

model = Sketchup.active_model
attrdicts = model.attribute_dictionaries
# Deletes a dictionary called 'my_dictionary'
attrdicts.delete 'my_dictionary'

Parameters:

Returns:

  • (AttributeDictionaries)

    the modified AttributeDictionaries

Raises:

  • ArgumentError if an advanced attribute dictionary is being deleted.

Version:

  • SketchUp 6.0

#each {|dictionary| ... } ⇒ Object

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

Examples:

model = Sketchup.active_model
dictionaries = model.attribute_dictionaries
# Iterates through all dictionaries and prints to screen.
dictionaries.each { |dictionary| puts dictionary.name }

Yield Parameters:

Returns:

  • nil

Version:

  • SketchUp 6.0

#lengthInteger

The #length method returns the number of attribute dictionary objects in the collection.

Examples:

model = Sketchup.active_model
model.set_attribute('Example', 'Hello', 'World')
dictionaries = model.attribute_dictionaries
number = dictionaries.length

Returns:

  • (Integer)

    the number of attribute dictionary objects in the collection.

See Also:

Version:

  • SketchUp 2014

#sizeInteger

The #size method is an alias of #length.

Examples:

model = Sketchup.active_model
model.set_attribute('Example', 'Hello', 'World')
dictionaries = model.attribute_dictionaries
number = dictionaries.size

See Also:

Version:

  • SketchUp 2014