SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Entity class

This is the base class for all SketchUp entities.

Parent: Object

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

Example Code: entitytests.rb 

Instance Methods



add_observer

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

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


attribute_dictionaries

The AttributeDictionaries is used to retrieve the attribute_dictionaries that are attached to the entity.

Syntax

attributedictionaries = entity.attribute_dictionaries 
 

Return Value

attributedictionaries - the AttributeDictionaries object associated with the entity, or nil if there are none.

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

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

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?

Return Value

status - true if deleted, false if not deleted

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 

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"

 

 


get_observers

The get_observers method is used to.

Syntax

 

Arguments

 

Return Value

 

Example

 

 


model 

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

Syntax

model = entity.model 

Return Value

model - the model that contains the Entity object

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 

Return Value

entity - a Entity object representing the parent of this entity

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

 

 



remove_observer

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

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


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 

Return Value

string - the string representation of the entity if successful

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 

Return Value

type - the type of the entity

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? 

Return Value

status - true if valid, false if invalid

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?

 

SketchUp  Ruby API Reference: Entity

© Google Inc. 2007 sketchup.google.com