Class: Sketchup::Entities

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb

Overview

The Entities class is a collection of Entity objects, either in a ComponentDefinition or directly in the Model. A Entities object corresponds to a drawing context in the GUI.

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#[](entity_index) ⇒ Sketchup::Entity?

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.length - 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.

Examples:

entities = Sketchup.active_model.entities
entity = entities[0]

See Also:

Version:

  • SketchUp 6.0



35
36
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 35

def [](entity_index)
end

#active_section_planeSketchup::SectionPlane?

The active_section_plane method is used to access the currently active section plane in the Entities object.

Examples:

entities = Sketchup.active_model.entities
section_plane = entities.add_section_plane([50, 50, 0], [1.0, 1.0, 0])
entities.active_section_plane = section_plane
section_plane = entities.active_section_plane

Version:

  • SketchUp 2014



50
51
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 50

def active_section_plane
end

#active_section_plane=(sec_plane) ⇒ Sketchup::SectionPlane?

The active_section_plane= method is used to set the active section plane in the Entities object.

Examples:

entities = Sketchup.active_model.entities
section_plane = entities.add_section_plane([50, 50, 0], [1.0, 1.0, 0])
entities.active_section_plane = section_plane

Version:

  • SketchUp 2014



68
69
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 68

def active_section_plane=(sec_plane)
end

#add_3d_text(string, alignment, font, is_bold = false, is_italic = false, letter_height = 1.0, tolerance = 0.0, z = 0.0, is_filled = true, extrusion = 0.0) ⇒ Boolean

The #add_3d_text method is used to create 3D text. It will be added as edges and faces drawn at the origin.

Examples:

# 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.inch, 0.0, 0.5.inch, true, 5.0.inch)

Version:

  • SketchUp 6.0



118
119
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 118

def add_3d_text(string, alignment, font, is_bold = false, is_italic = false, letter_height = 1.0, tolerance = 0.0, z = 0.0, is_filled = true, extrusion = 0.0)
end

#add_arc(center, xaxis, normal, radius, start_angle, end_angle) ⇒ Array<Sketchup::Edge> #add_arc(center, xaxis, normal, radius, start_angle, end_angle, num_segments) ⇒ Array<Sketchup::Edge>

The add_arc method is used to create an arc curve segment.

Examples:

model = Sketchup.active_model
entities = model.active_entities
center_point = Geom::Point3d.new
# Create an arc perpendicular to the normal or Z axis
normal = Geom::Vector3d.new(0, 0, 1)
xaxis = Geom::Vector3d.new(1, 0, 0)
edges = entities.add_arc(center_point, xaxis, normal, 10, 15.degrees, 135.degrees)

Version:

  • SketchUp 6.0



154
155
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 154

def add_arc(*args)
end

#add_circle(center, normal, radius, numsegs = 24) ⇒ Array<Sketchup::Edge>

The add_circle method is used to create a circle.

Examples:

model = Sketchup.active_model
entities = model.active_entities
center_point = Geom::Point3d.new
# Create a circle perpendicular to the provided vector.
normal = Z_AXIS
edges = entities.add_circle(center_point, vector, 10)

Version:

  • SketchUp 6.0



182
183
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 182

def add_circle(center, normal, radius, numsegs = 24)
end

#add_cline(start_point, end_point, stipple = '-') ⇒ Sketchup::ConstructionLine #add_cline(point, vector, stipple = '-') ⇒ Sketchup::ConstructionLine

The #add_cline method is used to create a construction line. This can be finite or infinite.

Examples:

model = Sketchup.active_model
entities = model.active_entities
point1 = Geom::Point3d.new(0, 0, 0)
point2 = Geom::Point3d.new(20, 20, 20)
cline = entities.add_cline(point1, point2)

Overloads:

Version:

  • SketchUp 6.0



214
215
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 214

def add_cline(*args)
end

#add_cpoint(point) ⇒ Sketchup::ConstructionPoint

The add_cpoint method is used to create a construction point.

Examples:

entities = Sketchup.active_model.active_entities
point1 = Geom::Point3d.new(100, 200, 300)
constpoint = entities.add_cpoint(point1)

Version:

  • SketchUp 6.0



231
232
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 231

def add_cpoint(point)
end

#add_curve(points) ⇒ Array<Sketchup::Edge> #add_curve(*points) ⇒ Array<Sketchup::Edge>

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.

Examples:

entities = Sketchup.active_model.entities
curve = entities.add_curve([0, 0, 0], [0, 10, 0], [10, 20, 0])

Version:

  • SketchUp 6.0



254
255
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 254

def add_curve(*args)
end

#add_dimension_linear(start_pt_or_entity, end_pt_or_entity, offset_vector) ⇒ Sketchup::DimensionLinear #add_dimension_linear(start_instance_path, end_instance_path, offset_vector) ⇒ Sketchup::DimensionLinear #add_dimension_linear(start_array, end_array, offset_vector) ⇒ Sketchup::DimensionLinear

The #add_dimension_linear method adds a linear dimension to the entities.

Examples:

entities = Sketchup.active_model.entities
# From point to point
dim = entities.add_dimension_linear([0, 0, 0], [50, 0, 0], [0, 20, 0])

# Between edge vertices
edge1 = entities.add_edges([70, 0, 0], [120, 0, 0])[0]
v0 = edge1.start
v1 = edge1.end
dim = entities.add_dimension_linear(v0, v1, [0, 20, 0])

# From an edge's midpoint to a construction point
edge2 = entities.add_edges([150, 0, 0], [200, 0, 0])[0]
p0 = edge2.start.position
p1 = edge2.end.position
mp = Geom::Point3d.new((p0.x + p1.x) / 2.0, (p0.y + p1.y) / 2.0, (p0.z + p1.z) / 2.0)
cp = entities.add_cpoint([150, 40, 0])
dim = entities.add_dimension_linear([edge2, mp], cp, [20, 0, 0])

Instance path

entities = Sketchup.active_model.entities
group = entities.add_group
group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
instance = group.to_component
transformation = instance.transformation
edge = instance.definition.entities.grep(Sketchup::Edge).first
instance_path = Sketchup::InstancePath.new([instance, edge])
start_point = edge.start.position.transform(transformation)
end_point = edge.end.position.transform(transformation)
vector = Geom::Vector3d.new(0, 30, 0)
Sketchup.active_model.entities.add_dimension_linear(
  [instance_path, start_point], [instance_path, end_point], vector)

Instance path as an array

entities = Sketchup.active_model.entities
group = entities.add_group
group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
instance = group.to_component
transformation = instance.transformation
edge = instance.definition.entities.grep(Sketchup::Edge).first
path = [instance, edge]
start_point = edge.start.position.transform(transformation)
end_point = edge.end.position.transform(transformation)
vector = Geom::Vector3d.new(0, 30, 0)
Sketchup.active_model.entities.add_dimension_linear(
  [path, start_point], [path, end_point], vector)

Overloads:

  • #add_dimension_linear(start_instance_path, end_instance_path, offset_vector) ⇒ Sketchup::DimensionLinear
    Note:

    Added in SketchUp 2019.

  • #add_dimension_linear(start_array, end_array, offset_vector) ⇒ Sketchup::DimensionLinear
    Note:

    Added in SketchUp 2019.

Version:

  • SketchUp 2014



352
353
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 352

def add_dimension_linear(*args)
end

#add_dimension_radial(arc_curve, leader_break_pt) ⇒ Sketchup::DimensionRadial

The add_dimension_radial method adds a radial dimension (i.e arc/circle radius/diameter dimension) to the entities.

Examples:

entities = Sketchup.active_model.entities
# Create a circle
center_point = Geom::Point3d.new(10, 10, 0)
vector = Geom::Vector3d.new(0, 0, 1)
edges = entities.add_circle(center_point, vector, 10)
circle = edges[0].curve
dim = entities.add_dimension_radial(circle, [30, 30, 0])

Version:

  • SketchUp 2014



378
379
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 378

def add_dimension_radial(arc_curve, leader_break_pt)
end

#add_edges(points) ⇒ Array<Sketchup::Edge> #add_edges(*points) ⇒ Array<Sketchup::Edge>

Note:

If the points form a closed loop, the first and last vertex will not merge. If you intend to create a face from the edges, use #add_face directly.

The #add_edges method is used to add a set of connected edges to the Sketchup::Entities collection.

Examples:

model = Sketchup.active_model
entities = model.active_entities
point1 = Geom::Point3d.new(0, 0, 0)
point2 = Geom::Point3d.new(20, 20, 20)
point3 = Geom::Point3d.new(20, 40, 20)
edges = entities.add_edges(point1, point2, point3)

See Also:

Version:

  • SketchUp 6.0



413
414
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 413

def add_edges(*args)
end

#add_face(entities) ⇒ Sketchup::Face? #add_face(*entities) ⇒ Sketchup::Face?

Note:

A special case exists for any face created on the ground plane, in which case the vertex order is ignored and the face is always facing down.

The add_face method is used to create a face. You can call this method a number of ways:

- entities.add_face(edge1, edge2, edge3, ...)
- entities.add_face(edgearray)
- entities.add_face(pt1, pt2, pt3, ...)
- entities.add_face([pt1, pt2, pt3,...])
- entities.add_face(curve)

For the last form that takes a Curve, the curve must be closed - like a circle.

Examples:

model = Sketchup.active_model
entities = model.active_entities
points = []
points << [0, 0, 0]
points << [100, 0, 0]
points << [100, 100, 0]
points << [0, 100, 0]
# Add the face to the entities in the model
face = entities.add_face(points)

See Also:

Version:

  • SketchUp 6.0



460
461
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 460

def add_face(*args)
end

#add_faces_from_mesh(polygon_mesh, smooth_flags = Geom::PolygonMesh::AUTO_SOFTEN|Geom::PolygonMesh::SMOOTH_SOFT_EDGES, f_material = nil, b_material = nil) ⇒ Integer

The #add_faces_from_mesh method is used to add Face entities to the collection of entities from a Geom::PolygonMesh.

The smooth_flags parameter can contain any of the following values if passed. The constants were added in SketchUp 2014. For previous versions, numeric values have to be specified instead of the Ruby constants.

The 3rd and 4th parameters will accept a Material object or a string name of a material currently in the model.

Examples:

pm = Geom::PolygonMesh.new
pm.add_point([ 0, 0, 0]) # 1
pm.add_point([10, 0, 0]) # 2
pm.add_point([10, 10, 0]) # 3
pm.add_point([0, 10, 0]) # 4
pm.add_point([20, 0, 5]) # 5
pm.add_point([20, 10, 5]) # 6
pm.add_polygon(1, -2, 3, 4)
pm.add_polygon(2, 5, 6, -3)

# Create a new group that we will populate with the mesh.
group = Sketchup.active_model.entities.add_group
material1 = Sketchup.active_model.materials.add('My Green Material')
material1.color = 'green'
material2 = Sketchup.active_model.materials.add('My Red Material')
material2.color = 'red'
smooth_flags = Geom::PolygonMesh::NO_SMOOTH_OR_HIDE
group.entities.add_faces_from_mesh(pm, smooth_flags, material1, material2)

See Also:

Version:

  • SketchUp 6.0



520
521
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 520

def add_faces_from_mesh(polygon_mesh, smooth_flags = Geom::PolygonMesh::AUTO_SOFTEN|Geom::PolygonMesh::SMOOTH_SOFT_EDGES, f_material = nil, b_material = nil)
end

#add_group(entities) ⇒ Sketchup::Group #add_group(*entities) ⇒ Sketchup::Group

Note:

Calling add_group with entities in its parameters has been known to crash SketchUp before version 8.0. It is preferable to create an empty group and then add things to its Entities collection.

The add_group method is used to create an empty group or a group with entities.

Examples:

model = Sketchup.active_model
entities = model.active_entities
group = entities.add_group

Version:

  • SketchUp 6.0



548
549
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 548

def add_group(*args)
end

#add_image(path, point, width, height = 0.0) ⇒ Sketchup::Image?

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.

Examples:

model = Sketchup.active_model
entities = model.active_entities
point = Geom::Point3d.new(10, 20, 30)
image = entities.add_image(Sketchup.find_support_file('ColorWheel.png',
  'Resources/../..'), point, 300)

Version:

  • SketchUp 6.0



582
583
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 582

def add_image(path, point, width, height = 0.0)
end

#add_instance(definition, transform) ⇒ Sketchup::ComponentInstance

The add_instance method adds a component instance to the collection of entities.

Examples:

model = Sketchup.active_model
entities = model.active_entities
point = Geom::Point3d.new(10, 20, 30)
transform = Geom::Transformation.new(point)
path = Sketchup.find_support_file("Bed.skp", "Components/Components Sampler/")
definitions = model.definitions
componentdefinition = definitions.load(path)
instance = entities.add_instance(componentdefinition, transform)

Version:

  • SketchUp 6.0



607
608
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 607

def add_instance(definition, transform)
end

#add_line(point1, point2) ⇒ Sketchup::Edge

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.

Examples:

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)

See Also:

Version:

  • SketchUp 6.0



641
642
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 641

def add_line(point1, point2)
end

#add_ngon(center, normal, radius, numsides = 24) ⇒ Array<Sketchup::Edge>

The add_ngon method is used to create a multi-sided polygon.

Examples:

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)

Version:

  • SketchUp 6.0



670
671
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 670

def add_ngon(center, normal, radius, numsides = 24)
end

#add_observer(observer) ⇒ Boolean

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

Examples:

# This is an example of an observer that watches the entities collection.
# It writes to the console everytime new entities are added to the model.
class MyEntitiesObserver < Sketchup::EntitiesObserver
  def onElementAdded(entities, entity)
    puts "onElementAdded: #{entity} was added to the model."
  end
end

# Attach the observer
entities = Sketchup.active_model.entities
entities.add_observer(MyEntitiesObserver.new)

Version:

  • SketchUp 6.0



694
695
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 694

def add_observer(observer)
end

#add_section_plane(plane) ⇒ Sketchup::SectionPlane?

The add_section_plane method adds a section plane object to the entities.

Examples:

# Create a section plane
model = Sketchup.active_model
section_plane = model.entities.add_section_plane([50, 50, 0], [1.0, 1.0, 0])
# Activate it
section_plane.activate
# Make sure section planes are visible
model.rendering_options['DisplaySectionPlanes'] = true

Version:

  • SketchUp 2014



717
718
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 717

def add_section_plane(plane)
end

#add_text(text, point, vector) ⇒ Sketchup::Text #add_text(text, instance_path_and_pt, vector) ⇒ Sketchup::Text #add_text(text, instance_array_and_pt, vector) ⇒ Sketchup::Text

The #add_text method adds a note or label text entity to the entities.

Examples:

model = Sketchup.active_model
entities = model.entities
point = Geom::Point3d.new(10, 10, 10)
text = entities.add_text("This is a Test", point)

Instance path

entities = Sketchup.active_model.entities
group = entities.add_group
group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
instance = group.to_component
transformation = instance.transformation
edge = instance.definition.entities.grep(Sketchup::Edge).first
instance_path = Sketchup::InstancePath.new([instance, edge])
point = edge.start.position.transform(transformation)
vector = Geom::Vector3d.new(45, 45, 45)
Sketchup.active_model.entities.add_text("mytext", [instance_path, point], vector)

Instance path as an array

entities = Sketchup.active_model.entities
group = entities.add_group
group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
instance = group.to_component
transformation = instance.transformation
edge = instance.definition.entities.grep(Sketchup::Edge).first
path = [instance, edge]
point = edge.start.position.transform(transformation)
vector = Geom::Vector3d.new(45, 45, 45)
Sketchup.active_model.entities.add_text("mytext", [path, point], vector)

Overloads:

  • #add_text(text, instance_path_and_pt, vector) ⇒ Sketchup::Text

    Version:

    • SketchUp 2019

  • #add_text(text, instance_array_and_pt, vector) ⇒ Sketchup::Text

    Version:

    • SketchUp 2019

Version:

  • SketchUp 6.0



785
786
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 785

def add_text(*args)
end

#at(entity_index) ⇒ Sketchup::Entity?

The #at method is an alias for #[].

Examples:

entities = Sketchup.active_model.entities
entity = entities.at(0)

See Also:

Version:

  • SketchUp 6.0



802
803
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 802

def at(entity_index)
end

#build {|builder| ... } ⇒ nil

Note:

While using #build it is important to not add or remove vertices by other means of the builder. Also don’t modify the position of the vertices in the Sketchup::Entities container geometry is added to. Doing so can break the vertex-cache that de-duplicates the vertices.

Creates an Sketchup::EntitiesBuilder that can be used to generate bulk geometry with performance in mind. This is particularly useful for importers where the geometry is already well defined and one wants to recreate it without further processing.

The call to #build starts an implicit operation, even if no other model changes are made within the block. This is not the same as Model#start_operation, so it’s still recommended to wrap all model changes, including #build with Model#start_operation and Model#commit_operation.

Refer to the documentation of Sketchup::EntitiesBuilder for more details.

Examples:

model = Sketchup.active_model
model.entities.build { |builder|
  edge = builder.add_edge([0, 0, 0], [9, 0, 0])
  edge.material = 'red'
  face = builder.add_face([0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0])
  face.material = 'maroon'
}

Yields:

  • (builder)

Yield Parameters:

See Also:

Version:

  • SketchUp 2022.0



841
842
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 841

def build
end

#clear!Boolean

The clear! method is used to remove all entities from the collection of entities.

Examples:

entities = Sketchup.active_model.entities
status = entities.clear!

Version:

  • SketchUp 6.0



854
855
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 854

def clear!
end

#countInteger

Note:

Since SketchUp 2014 the count method is inherited from Ruby’s Enumerable mix-in module. Prior to that the #count method is an alias for #length.

Examples:

entities = Sketchup.active_model.entities
number = entities.count

See Also:

Version:

  • SketchUp 6.0



871
872
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 871

def count
end

#each {|entity| ... } ⇒ nil

Note:

Don’t remove content from this collection while iterating over it with #each. This would change the size of the collection and cause elements to be skipped as the indices change. Instead copy the current collection to an array using to_a and then use each on the array, when removing content.

The #each method is used to iterate through the entities in the collection of entities.

Examples:

model = Sketchup.active_model
entities = model.entities
entities.each { | entity| puts entity }

Yield Parameters:

Version:

  • SketchUp 6.0



892
893
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 892

def each
end

#erase_entities(entities) ⇒ nil #erase_entities(*entities) ⇒ nil

Note:

It’s faster to use this method and erase in bulk than to iterate individual drawing elements calling Drawingelement#erase!.

The #erase_entities method is used to erase one or more entities from the model.

Examples:

model = Sketchup.active_model
entities = model.active_entities
points = []
points << [0, 0, 0]
points << [100, 0, 0]
points << [100, 100, 0]
points << [0, 100, 0]

# Add the face to the entities in the model.
face = entities.add_face(pts)
faces = entities.grep(Sketchup::Face)
entities.erase_entities(faces)

Raises:

  • (ArgumentError)

    if the given entities contains instances or definitions are used by Model#active_path.

Version:

  • SketchUp 6.0



932
933
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 932

def erase_entities(*args)
end

#fill_from_mesh(polygon_mesh, weld_vertices = true, smooth_flags = Geom::PolygonMesh::AUTO_SOFTEN|Geom::PolygonMesh::SMOOTH_SOFT_EDGES, f_material = nil, b_material = nil) ⇒ Boolean

The #fill_from_mesh method is used to add faces and edges to the collection of entities from a Geom::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 smooth_flags parameter can contain any of the following values if passed. The constants were added in SketchUp 2014. For previous versions, numeric values have to be specified instead of the Ruby constants:

The 4rd and 5th parameters will accept a Material object or a string name of a material currently in the model.

Examples:

pm = Geom::PolygonMesh.new
pm.add_point([  0,  0, 0]) # 1
pm.add_point([ 10,  0, 0]) # 2
pm.add_point([ 10, 10, 0]) # 3
pm.add_point([  0, 10, 0]) # 4
pm.add_point([ 20,  0, 5]) # 5
pm.add_point([ 20, 10, 5]) # 6
pm.add_polygon(1, -2, 3, 4)
pm.add_polygon(2, 5, 6, -3)

# Create a new group that we will populate with the mesh.
group = Sketchup.active_model.entities.add_group
material = Sketchup.active_model.materials.add('My Red Material')
material.color = 'red'
smooth_flags = Geom::PolygonMesh::HIDE_BASED_ON_INDEX
group.entities.fill_from_mesh(pm, true, smooth_flags, material)

See Also:

Version:

  • SketchUp 6.0



998
999
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 998

def fill_from_mesh(polygon_mesh, weld_vertices = true, smooth_flags = Geom::PolygonMesh::AUTO_SOFTEN|Geom::PolygonMesh::SMOOTH_SOFT_EDGES, f_material = nil, b_material = nil)
end

#intersect_with(recurse, transform1, entities1, transform2, hidden, entities2) ⇒ nil

The intersect_with method is used to intersect an entities, component instance, or group object with a entities object.

Examples:

model = Sketchup.active_model
entities = model.active_entities

# Create a group to intersect with the model
group1 = entities.add_group
face1 = group1.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
face1.pushpull(-40)

# Add geometry into the model
face2 = entities.add_face([50, 50, 0], [200, 50, 0], [200, 200, 0], [50, 200, 0])
face2.pushpull(-100)

entities1 = group1.entities
entities2 = entities.to_a

transformation1 = Geom::Transformation.new
transformation2 = group1.transformation

# Intersect the group and model geometry
entities.intersect_with(true, transformation1, entities1, transformation2, true, entities2)

Version:

  • SketchUp 6.0



1051
1052
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1051

def intersect_with(recurse, transform1, entities1, transform2, hidden, entities2)
end

#lengthInteger

The #length method is used to retrieve the number of entities in the collection of entities.

Examples:

model = Sketchup.active_model
entities = model.entities
number = entities.length

See Also:

Version:

  • SketchUp 6.0



1067
1068
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1067

def length
end

#modelSketchup::Model

The model method is used to retrieve the model that contains the collection of entities.

Examples:

model = Sketchup.active_model
entities = model.entities
group = entities.add_group
face = group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
model = group.entities.model

Version:

  • SketchUp 6.0



1084
1085
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1084

def model
end

#parentSketchup::ComponentDefinition, Sketchup::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.

Examples:

model = Sketchup.active_model
entities = model.entities
group = entities.add_group
face = group.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
model = group.entities.parent

Version:

  • SketchUp 6.0



1102
1103
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1102

def parent
end

#remove_observer(observer) ⇒ Boolean

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

Examples:

# This is an example of an observer that watches the entities collection.
# It writes to the console everytime new entities are added to the model.
class MyEntitiesObserver < Sketchup::EntitiesObserver
  def onElementAdded(entities, entity)
    puts "onElementAdded: #{entity} was added to the model."
  end
end

# Attach the observer
entities = Sketchup.active_model.entities
my_observer = MyEntitiesObserver.new
entities.add_observer(my_observer)
# Add an entity to the model, and the observer will trigger.
entities.add_line([0,0,0], [100,0,0])
# Remove the oberserver and the observer will no longer trigger.
status = entities.remove_observer(my_observer)

Version:

  • SketchUp 6.0



1132
1133
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1132

def remove_observer(observer)
end

#sizeInteger

The #size method is an alias for the #length method.

Examples:

model = Sketchup.active_model
entities = model.entities
entities.size

See Also:

Version:

  • SketchUp 2014



1147
1148
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1147

def size
end

#transform_by_vectors(sub_entities, vectors) ⇒ Sketchup::Entities

The transform_by_vectors method is used to apply several vectors to several sub-entities all at once.

Examples:

model = Sketchup.active_model
entities = model.active_entities

# Create a group with geometry to transform
group1 = entities.add_group
face1 = group1.entities.add_face([0, 0, 0], [100, 0, 0], [100, 100, 0], [0, 100, 0])
face1.pushpull(-40)

# Raise vertices in selection by their distance to the origin.
with_vertices = group1.entities.select { |entity| entity.respond_to?(:vertices) }
vertices = with_vertices.flat_map(&:vertices).uniq
lengths = vertices.map { |vertex| vertex.position.distance(ORIGIN) }
vectors = lengths.map { |length| Geom::Vector3d.new(0, 0, length) }

entities.transform_by_vectors(vertices, vectors)

Version:

  • SketchUp 6.0



1179
1180
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1179

def transform_by_vectors(sub_entities, vectors)
end

#transform_entities(transform, entities) ⇒ Boolean

The transform_entities method is used to apply a transform to several sub-entities all at once.

If you are transforming entities in the active drawing context or any of its parent drawing contexts, the transformation will be interpreted as relative to the global coordinate system. Otherwise the transformation will be interpreted as being on the local coordinate system.

Examples:

entities = Sketchup.active_model.entities
# Add edges to the model at the origin.
edge1 = entities.add_line([0, 0, 0], [100, 100, 100])
edge2 = entities.add_line([0, 0, 0], [200, -10, -10])

# After the transformation, the edges will be moved 100 inches
# away from the origin, on the x axis.
transformation = Geom::Transformation.new([100, 0, 0])
entities.transform_entities(transformation, [edge1, edge2])

Version:

  • SketchUp 6.0



1210
1211
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1210

def transform_entities(transform, entities)
end

#weld(edges) ⇒ Array<Sketchup::Curve>

The #weld method takes a set of edges and find all possible chains of edges and connect them with a Curve.

A curve will not cross another curve. They will split where multiple curves meet.

Examples:

model = Sketchup.active_model
entities = model.active_entities
edges = []
edges << entities.add_line([0, 0, 0], [100, 20, 0])
edges << entities.add_line([100, 20, 0], [130, 200, 50])
edges << entities.add_line([130, 200, 50], [130, 300, 50])
curves = model.active_entities.weld(edges)

Raises:

  • (ArgumentError)

    if the given entities are not part of the same Sketchup::Entities collection.

Version:

  • SketchUp 2020.1



1236
1237
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Entities.rb', line 1236

def weld(edges)
end