|
SketchUp Ruby API Reference |
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
The add_observer method is used to add an observer to the current object.
status = object.add_observer observer
observer - an observer
true if successful, false if unsuccessful.
The AttributeDictionaries is used to retrieve the attribute_dictionaries that are attached to the entity.
attributedictionaries = entity.attribute_dictionaries
attributedictionaries - the AttributeDictionaries object associated with the entity, or nil if there are none.
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
The AttributeDictionary method is used to retrieve an attribute dictionary with a given name that is attached to an Entity.
attributedictionary = entity.attribute_dictionary name, <create_if_needed>
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.
attributedictionary - an AttributeDictionary object if successful, or nil if there is no attribute dictionary
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"
The delete_attribute method is used to delete an attribute from an entity.
status = entity.delete_attribute "dictionary_name"
status = entity.delete_attribute "dictionary_name", key
"dictionary_name" - the name of an attribute dictionary
key - an attribute key
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.
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"
The deleted? method is used to determine if your entity is still valid (not deleted by another script, for example).
status = entity.deleted?
status - true if deleted, false if not deleted
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?
The entityID method is used to retrieve a unique ID assigned to an entity.
id = entity.entityID
id - the id for the Entity object
The entityID is not persistent between sessions.
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
The get_attribute method is used to retrieve the value of an attribute in the entity's attribute dictionary.
value = entity.get_attribute "dictionary_name", key
value = entity.get_attribute "dictionary_name", key, default_value
"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
value - the retrieved value
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.
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"
The get_observers method is used to.
The model method is used to retrieve model for the entity.
model = entity.model
model - the model that contains the Entity object
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
The parent method is used to retrieve the parent entity of the entity.
entity = entity.parent
entity - a Entity object representing the parent of this entity
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
The remove_observer method is used to remove an observer from the current object.
status = object.remove_observer observer
observer - an observer
true if successful, false if unsuccessful.
The set attribute is used to set the value of an attribute in an attribute dictionary with the given name.
value = entity.set_attribute "dictionary_name", key, value
"dictionary_name" - the name of an attribute dictionary
key - an attribute key
value - the value for the attribute
value - the newly set value if successful
This method will create a new AttributeDictionary if none exists.
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
The to_s method is used to retrieve the string representation of the entity.
string = entity.to_s
string - the string representation of the entity if successful
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
The typename method retrieves the type of the entity.
type = entity.typename
type - the type of the entity
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
The valid? method is used to verify that an entity is valid (not deleted).
status = entity.valid?
status - true if valid, false if invalid
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?