My favorites | English | Sign in

Google SketchUp Ruby API

Entity

class

Parent: Object

Introduction

SketchUp 6.0+

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.")

Methods

Entity.add_observerSketchUp 6.0+

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

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 entity = Sketchup.active_model.entities[0]
 if entity.valid?
   status = entity.add_observer observer
 end

Entity.attribute_dictionariesSketchUp 6.0+

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

Returns:

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

Entity.attribute_dictionarySketchUp 6.0+

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

Arguments:

name
The name of the attribute dictionary.
create
(optional) boolean, if set to true then the attribute dictionary will be created if it does not exist.

Returns:

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"

Entity.delete_attributeSketchUp 6.0+

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:

dictionary_name
The name of an attribute dictionary.
key
An attribute key.

Returns:

nil
 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"

Entity.deleted?SketchUp 6.0+

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

Returns:

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?

Entity.entityIDSketchUp 6.0+

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

The entityID is not persistent between sessions.

Returns:

id
the id for 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
 entity1 = entities[1]        
 id = entity1.entityID

Entity.get_attributeSketchUp 6.0+

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:

dict_name
The name of an attribute dictionary.
key
An attribute key.
default_value
(optional) A default value to return if no attribute is found.

Returns:

value
the retrieved value
 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"

Entity.modelSketchUp 6.0+

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

Returns:

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

Entity.parentSketchUp 6.0+

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:

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

Entity.remove_observerSketchUp 6.0+

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

Arguments:

observer
An observer.

Returns:

true if successful, false if unsuccessful.
 entity = Sketchup.active_model.entities[0]
 if entity.valid?
   status = entity.remove_observer observer
 end

Entity.set_attributeSketchUp 6.0+

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:

dict_name
The name of an attribute dictionary.
key
An attribute key.
value
The value for the attribute.

Returns:

value
the newly set value 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]
 status = entity1.set_attribute "testdictionary", "test", 115

Entity.to_sSketchUp 6.0+

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

Returns:

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

Entity.typenameSketchUp 6.0+

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

Returns:

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

Entity.valid?SketchUp 6.0+

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:

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.valid?