Entity

class Entity

Parent: Object | Class Index
Methods:attribute_dictionaries, attribute_dictionary,delete_attribute, deleted?, entityID, get_attribute, model, parent, set_attribute, to_s, typename, valid? |
Sample Code: entitytests.rb |

This is the base class for all SketchUp entities.

Instance Methods

attribute_dictionaries
The AttributeDictionaries is used to retrieve the attribute_dictionaries that are attached to the entity.
Syntax:
attributedictionaries = entity.attribute_dictionaries
Arguments:
Return Value:
attributedictionaries - the AttributeDictionaries object associated with the entity, or nil if there are none.
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.set_attribute "testdictionary", "test", 115
attrdicts = entity1.attribute_dictionaries

attribute_dictionary
The AttributeDictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.
Syntax:
attributedictionary = entity.attribute_dictionary name, <create_if_needed>
Arguments:
name - the name of the attribute dictionary <create_if_needed> - (optional) flag; if set to true then the attribute dictionary will be created if it does not exist.
Return Value:
attributedictionary - an AttributeDictionary object if successful, or nil if there is no attribute dictionary
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.set_attribute "testdictionary", "test", 115
attrdict = entity1.attribute_dictionary "testdictionary"

delete_attribute
The delete_attribute method is used to delete an attribute from an entity.
Syntax:
status = entity.delete_attribute "dictionary_name" status = entity.delete_attribute "dictionary_name", key
Arguments:
"dictionary_name" - the name of an attribute dictionary key - an attribute key
Return Value:
Comments:
If only the dictionary_name is given, then it deletes the entire AttributeDictionary. Otherwise, delete_attribute deletes the attribute with the given key from the given dictionary.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.set_attribute "testdictionary", "test", 115
status = entity1.delete_attribute "testdictionary"

deleted?
The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example).
Syntax:
status = entity.deleted?
Arguments:
Return Value:
status - true if deleted, false if not deleted
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
entity1 = entities[1]
status = entity1.deleted?

entityID
The entityID method is used to retrieve a unique ID assigned to an entity.
Syntax:
id = entity.entityID
Arguments:
Return Value:
id - the id for the Entity object
Comments:
The entityID is not persistent between sessions.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
entity1 = entities[1]
id = entity1.entityID

get_attribute
The get_attribute method is used to retrieve the value of an attribute in the entity's attribute dictionary.
Syntax:
value = entity.get_attribute "dictionary_name", key value = entity.get_attribute "dictionary_name", key, default_value
Arguments:
"dictionary_name" - the name of an attribute dictionary key - an attribute key default_value - a default value to return if there is no attribute found
Return Value:
value - the retrieved value
Comments:
In the first form, if there is no attribute that matches the given names, it returns nil. In the second form, if there is no attribute, it returns the given default value. It does not create an attribute with that name though.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.set_attribute "testdictionary", "test", 115
value = entity1.get_attribute "testdictoinary", "test"

model
The model method is used to retrieve model for the entity.
Syntax:
model = entity.model
Arguments:
Return Value:
model - the model that contains the Entity object
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
m = entity1.model

parent
The parent method is used to retrieve the parent entity of the entity.
Syntax:
entity = entity.parent
Arguments:
Return Value:
entity - a Entity object representing the parent of this entity
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
parent = entity1.parent

set_attribute
The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.
Syntax:
value = entity.set_attribute "dictionary_name", key, value
Arguments:
"dictionary_name" - the name of an attribute dictionary key - an attribute key value - the value for the attribute
Return Value:
value - the newly set value if successful
Comments:
This method will create a new AttributeDictionary if none exists.
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.set_attribute "testdictionary", "test", 115

to_s
The to_s method is used to retrieve the string representation of the entity.
Syntax:
string = entity.to_s
Arguments:
Return Value:
string - the string representation of the entity if successful
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
st = entity1.to_s

typename
The typename method retrieves the type of the entity.
Syntax:
type = entity.typename
Arguments:
Return Value:
type - the type of the entity
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
type = entity1.typename

valid?
The valid? method is used to verify that an entity is valid (not deleted).
Syntax:
status = entity.valid?
Arguments:
Return Value:
status - true if valid, false if invalid
Comments:
Example:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]
# Add the face to the entities in the model
face = entities.add_face pts
# I just happen to know that the second and third entities in the
# entities objects are edges.
entity1 = entities[1]
status = entity1.valid?