The Entities class is a container class for all entities in a model (it is a collection of Entity objects).
The [] method is used to retrieve an entity by its index in an array of entities. The index is a number between 0 and entities.count - 1. In general, it is preferable to use the "each" method to iterate though all of the entities in the collection as it will be much more efficient.
Arguments:
Returns:
entities = Sketchup.active_model.entities entity0 = entities[0] if (entity0) UI.messagebox entity0 else UI.messagebox "Failure" end
The add_3d_text is used to create 3D text. It will be added as edges and faces drawn at the origin.
Arguments:
Returns:
# Draw the word "test" at the origin of the model, aligned left, in
# Arial Bold, not italics, 1" in size, best tolerance quality, filled,
# with an extrusion size of 5".
entities = Sketchup.active_model.entities
success = entities.add_3d_text('test', TextAlignLeft, "Arial",
true, false, 1.0, 0.0, 0.5, true, 5.0)The add_arc method is used to create an arc curve segment.
Arguments:
Returns:
centerpoint = Geom::Point3d.new # Create a circle perpendicular to the normal or Z axis vector = Geom::Vector3d.new 0,0,1 vector2 = Geom::Vector3d.new 1,0,0 vector3 = vector.normalize! model = Sketchup.active_model entities = model.active_entities arccurve = entities.add_arc centerpoint, vector2, vector3, 10, 15, 35 UI.messagebox arccurve
The add_circle method is used to create a circle.
Arguments:
Returns:
centerpoint = Geom::Point3d.new # Create a circle perpendicular to the normal or Z axis vector = Geom::Vector3d.new 0,0,1 vector2 = vector.normalize! model = Sketchup.active_model entities = model.active_entities edges = entities.add_circle centerpoint, vector2, 10
The add_cline method is used to create a construction line.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) constline = entities.add_cline point1,point2 if (constline) UI.messagebox constline else UI.messagebox "Failure" end
The add_cpoint method is used to create a construction point.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (100,200,300) constpoint = entities.add_cpoint point1 if (constpoint) UI.messagebox constpoint else UI.messagebox "Failure" end
The add_curve method is used to create a curve from a collection of edges.
The arguments are either Points or an Array of Points. At least 2 points are
required.
Arguments:
Returns:
entities = Sketchup.active_model.entities curve = entities.add_curve [0,0,0], [0,10,0], [1,20,0]
The add_edges method is used to add a set of connected edges to the entities array.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) edges = entities.add_edges point1, point2
The add_face method is used to create a face. You can call this method a
number of ways:
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 if (face) UI.messagebox face else UI.messagebox "Failure" end
The add_faces_from_mesh method is used to add Face objects to the collection
of entities from a PolygonMesh.
The 2nd through 4th parameters are optional. The smooth_flags parameter
can contain any of the following values if passed.
Arguments:
Returns:
# Grab a mesh from a face. pts = [] pts.push[0,0,0] pts.push[0,9,0] pts.push[9,9,0] pts.push[9,0,0] my_face = Sketchup.active_model.entities.add_face pts my_mesh = my_face.mesh # Create a new group that we will populate with the mesh. group = Sketchup.active_model.entities.add_group f_material = Sketchup.active_model.materials[0] f_material.color = "green" group.add_faces_from_mesh my_mesh, 0, f_material
The add_group method is used to create an empty group or a group with
entities.
NOTE: calling add_group with entities in its parameters has been known to
crash SketchUp. It is preferable to create an empty group and then add
things to its Entities collection.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities group = entities.add_group if (group) UI.messagebox group else UI.messagebox "Failure" end
The add_image method is used to add an image to the collection of entities.
The width and height are measured in model units (i.e. inches). If the
height is not given, then it is computed from the width to preserve the
aspect ratio of the image.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities point = Geom::Point3d.new 10,20,30 image = entities.add_image "Shapes.jpg", point, 300 if (image) UI.messagebox image else UI.messagebox "Failure" end
The add_instance method adds a component instance to the collection of entities.
Arguments:
Returns:
point = Geom::Point3d.new 10,20,30 transform = Geom::Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "Bed.skp", "Components/Components Sampler/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform if (instance) UI.messagebox instance else UI.messagebox "Failure" end
The add_line method is used to add an edge to the collection of entities.
This is not to be confused with the concept of a "line" from a geometric
sense, which is an invisible object represented by an Array of a point
and a vector. (See the Array class for more information on geometric lines in
SketchUp.)
This method is the same as add_edges method, but returns a single edge.
Arguments:
Returns:
model = Sketchup.active_model entities = model.active_entities point1 = Geom::Point3d.new (0,0,0) point2 = Geom::Point3d.new (20,20,20) line = entities.add_line point1,point2 if (line) UI.messagebox line else UI.messagebox "Failure" end
The add_ngon method is used to create a multi-sided polygon.
Arguments:
Returns:
entities = Sketchup.active_model.entities center = Geom::Point3d.new normal = Geom::Vector3d.new(0,0,1) radius = 100 numsides = 6 edges = entities.add_ngon center, normal, radius, numsides
The add_observer method is used to add an observer to the current object.
Arguments:
Returns:
entities = Sketchup.active_model.entities status = entities.add_observer observer
The add_text method adds a note or label text entity to the entities
Arguments:
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point
The at method is an alias for []. See [].
Returns:
entities = Sketchup.active_model.entities entity0 = entities.at(0) if (entity0) UI.messagebox entity0 else UI.messagebox "Failure" end
The clear! method is used to remove all entities from the collection of entities.
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point UI.messagebox "Clearing All" status = entities.clear!
The count method is an alias for the length method. See length.
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point length = entities.count
The each method is used to iterate through the entities in the collection of entities.
Arguments:
Returns:
coordinates = [10, 10, 10]
model = Sketchup.active_model
entities = model.entities
point = Geom::Point3d.new coordinates
text = entities.add_text "This is a Test", point
entities.each { | entity| UI.messagebox entity }The erase_entities method is used to erase one or more entities from the model.
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 entity in the # entities objects is an edge, so erase it. UI.messagebox entities entities.erase_entities entities[1] UI.messagebox entities
The fill_from_mesh method is used to add faces and edges to the collection of
entities from a PolygonMesh. It requires that the entities collection to be
filled is empty. It has higher performance than add_faces_from_mesh, but
does less error checking as it builds the geometry.
The 2nd through 5th parameters are optional. The smooth_flags parameter
can contain any of the following values if passed.
Arguments:
Returns:
# Grab a mesh from a face. pts = [] pts.push[0,0,0] pts.push[0,9,0] pts.push[9,9,0] pts.push[9,0,0] my_face = Sketchup.active_model.entities.add_face pts my_mesh = my_face.mesh # Create a new group that we will populate with the mesh. group = Sketchup.active_model.entities.add_group f_material = Sketchup.active_model.materials[0] f_material.color = "red" group.fill_from_mesh my_mesh, true, 12, f_material
The intersect_with method is used to intersect an entities, component instance, or group object with a entities object.
Arguments:
Returns:
entities.intersect_with recurse, transformation1, entities1, transformation2, hidden, entities2
The length method is used to retrieve the number of entities in the collection of entities.
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point length = entities.length
The model method is used to retrieve the model that contains the collection of entities.
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point model = entities.model
The parent method is used to retrieve the parent or object that contains the collection of entities. A parent can be either a Model or ComponentDefinition object.
Returns:
coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point parent = entities.parent
The remove_observer method is used to remove an observer from the current object.
Arguments:
Returns:
entities = Sketchup.active_model.entities status = entities.remove_observer observer
The transform_by_vectors method is used to apply several vectors to several sub-entities all at once.
Arguments:
Returns:
# Need better Ruby example. entities = entities.transform_by_vectors sub_entities, vector_array
The transform_entities method is used to apply a transform to several sub-entities all at once.
Arguments:
Returns:
entities = Sketchup.active_model.entities entities.add_line([0,0,0],[100,100,100]) entities.add_line([0,0,0],[200,-10,-10]) entities_to_transform = [] entities_to_transform.push(entities[0]) entities_to_transform.push(entities[1]) transform = Geom::Transformation.new([100,0,0]) entities.transform_entities(transform, ent1, ent2, ent3)