This is the base class for all SketchUp entities. Entities are basically
anything that can be contained in a model, including Drawingelements
such as Edges, SectionPlanes, Groups, etc. and entities that relate to
those Drawingelements, such as Loops, Layers, etc.
Keep in mind that the methods below are available on all subclasses.
For example, an Edge's parent class is Drawingelement, and a
Drawingelement's parent class is Entity. Therefore an Edge has all of the
methods defined in Drawingelement and Entity.
The typename method is the common way of determining what sort of Entity
you're dealing with.
# Count how many faces are in the current selection.
selection = Sketchup.active_model.selection
face_count = 0
# Look at all of the entities in the selection.
selection.each { |entity|
if entity.typename == "Face"
face_count = face_count + 1
end
}
UI.messagebox("There are " + face_count.to_s + " faces selected.")The add_observer method is used to add an observer to the current object.
Arguments:
Returns:
entity = Sketchup.active_model.entities[0] if entity.valid? status = entity.add_observer observer end
The attribute_dictionaries method is used to retrieve the AttributeDictionaries collection attached to the entity.
Returns:
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.
Arguments:
Returns:
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.
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.
Arguments:
Returns:
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.)
Returns:
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.
The entityID is not persistent between sessions.
Returns:
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.
If the third parameter, default_value, is not passed and there is no
attribute that matches the given name, it returns nil.
If default_value is provided and there is no matching attribute it returns
the given value. It does not create an attribute with that name though.
Arguments:
Returns:
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 model method is used to retrieve the model for the entity.
Returns:
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 of the entity.
The parent will be a ComponentDefinition, a Group, or a Model, whatever
the entity is contained within.
Returns:
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.
Arguments:
Returns:
entity = Sketchup.active_model.entities[0] if entity.valid? status = entity.remove_observer observer end
The set attribute is used to set the value of an attribute in an attribute
dictionary with the given name.
This method will create a new AttributeDictionary if none exists.
Arguments:
Returns:
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.
Returns:
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, which will be a string such as "Face", "Edge", or "Group".
Returns:
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 determine if your entity is still valid (not
deleted by another script, for example.)
This method is functionally identical to the deleted? method.
Returns:
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.valid?