Class: Sketchup::Face

Inherits:
Drawingelement show all
Defined in:
lib/sketchup-api-stubs/stubs/Sketchup/Face.rb

Overview

Faces in SketchUp are flat, 2-sided polygons with 3 or more sides.

Version:

  • SketchUp 6.0

Constant Summary collapse

PointInside =

Constants

nil
PointNotOnPlane =

Stub value.

nil
PointOnEdge =

Stub value.

nil
PointOnFace =

Stub value.

nil
PointOnVertex =

Stub value.

nil
PointOutside =

Stub value.

nil
PointUnknown =

Stub value.

nil

Instance Method Summary collapse

Methods inherited from Drawingelement

#bounds, #casts_shadows=, #casts_shadows?, #erase!, #hidden=, #hidden?, #layer, #layer=, #receives_shadows=, #receives_shadows?, #visible=, #visible?

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #parent, #persistent_id, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#all_connectedArray<Sketchup::Entity>

The all_connected method retrieves all of the entities connected to a face.

Examples:

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)
connected = face.all_connected

Version:

  • SketchUp 6.0



41
42
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 41

def all_connected
end

#areaFloat #area(transform) ⇒ Float

The area method is used to retrieve the area of a face.

You can pass in an optional Transformation (or an array that can represent a transformation), to correct for a parent group’s transformation. For example, if a face is inside of a group that is scaled to 200%, the area method will return the unscaled area of the face. So by passing a 200% transformation object to this method, you can account for that to get the “visual” area of the face.

Examples:

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)
area = face.area

Overloads:

  • #area(transform) ⇒ Float

    A Transformation object or array that can be interpreted as a Transformation object.

Version:

  • SketchUp 6.0



79
80
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 79

def area(*args)
end

#back_materialSketchup::Material?

The back_material method is used to retrieve the material assigned to the back side of the face.

Examples:

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)

# Add a material to the back face, then check to see that it was added
face.back_material = "red"
material = face.back_material

Version:

  • SketchUp 6.0



107
108
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 107

def back_material
end

#back_material=(material) ⇒ Sketchup::Material

The back_material= method is used to set the material assigned to the back side of the face.

Examples:

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)
status = face.back_material = "red"

Version:

  • SketchUp 6.0



134
135
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 134

def back_material=(material)
end

#classify_point(point) ⇒ Integer

The classify_point method is used to determine if a given Point3d is on the referenced Face.

It is important that return value comparisons be made against the symbolic constants (i.e. PointUnknown, PointInside, PointOnVertex, etc.) rather than the absolute integer values as these values may change from one release to the next.

Examples:

model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [9, 0, 0]
pts[2] = [9, 9, 0]
pts[3] = [0, 9, 0]

# Add the face to the entities in the model
face = entities.add_face(pts)

# Check a point that should be outside the face.
pt = Geom::Point3d.new(50, 50, 0)
result = face.classify_point(pt)
if result == Sketchup::Face::PointOutside
  puts "#{pt.to_s} is outside the face"
end

# Check a point that should be outside inside the face.
pt = Geom::Point3d.new(1, 1, 0)
result = face.classify_point(pt)
if result == Sketchup::Face::PointInside
  puts "#{pt.to_s} is inside the face"
end

# Check a point that should be on the vertex of the face.
pt = Geom::Point3d.new(0, 0, 0)
result = face.classify_point(pt)
if result == Sketchup::Face::PointOnVertex
  puts "#{pt.to_s} is on a vertex"
end

# Check a point that should be on the edge of the face.
pt = Geom::Point3d.new(0, 1, 0)
result = face.classify_point(pt)
if result == Sketchup::Face::PointOnEdge
  puts "#{pt.to_s} is on an edge of the face"
end

# Check a point that should be off the plane of the face.
pt = Geom::Point3d.new(1, 1, 10)
result = face.classify_point(pt)
if result == Sketchup::Face::PointNotOnPlane
  puts "#{pt.to_s} is not on the same plane as the face"
end

Version:

  • SketchUp 6.0



200
201
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 200

def classify_point(point)
end

#clear_texture_projection(frontside) ⇒ Object

The #clear_texture_projection method is used to clear the texture projection. This is similar to toggling off Projection from the Position Texture tool in the UI.

See Also:

Version:

  • SketchUp 2021.1



215
216
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 215

def clear_texture_projection(frontside)
end

#edgesArray<Sketchup::Edge>

The edges method is used to get an array of edges that bound the face.

Examples:

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)
edges = face.edges

Version:

  • SketchUp 6.0



237
238
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 237

def edges
end

#followme(edges) ⇒ Boolean #followme(edge) ⇒ Boolean

The #followme method is used to create a shape by making the face follow along an array of edges.

Examples:

model = Sketchup.active_model
entities = model.active_entities

depth = 100
width = 100

# Add the face to the entities in the model
points = [
  Geom::Point3d.new(0, 0, 0),
  Geom::Point3d.new(width, 0, 0),
  Geom::Point3d.new(width, depth, 0),
  Geom::Point3d.new(0, depth, 0)
]
face = entities.add_face(points)

# Add the line which we will "follow" to the entities in the model
point1 = Geom::Point3d.new(0, 0, 0)
point2 = Geom::Point3d.new(0, 0, 100)
edge = entities.add_line(point1, point2)
face.followme(edge)

Version:

  • SketchUp 6.0



276
277
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 276

def followme(*args)
end

#get_glued_instancesArray<Sketchup::ComponentInstance, Sketchup::Group, Sketchup::Image>

The get_glued_instances method returns an Array any ComponentInstances that are glued to the face.

Examples:

# Create a series of points that define a new face.
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [9, 0, 0]
pts[2] = [9, 9, 0]
pts[3] = [0, 9, 0]

# Add the face to the entities in the model
face = entities.add_face(pts)
glued_array = face.get_glued_instances

Version:

  • SketchUp 7.0 M1



346
347
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 346

def get_glued_instances
end

#get_texture_projection(frontside) ⇒ Geom::Vector3d?

The #get_texture_projection method will return a vector representing the projection for either the front or back side of the face.

Examples:

model = Sketchup.active_model
entities = model.active_entities
materials = model.materials

# Create a face and add it to the model entities
pts = []
pts[0] = [0, 0, 1]
pts[1] = [10, 0, 1]
pts[2] = [10, 10, 1]
face = entities.add_face(pts)

# Export an image to use as a texture
path = Sketchup.temp_dir
full_name = File.join(path, "temp_image.jpg")
model.active_view.write_image(full_name, 500, 500, false, 0.0)

# Create a material and assign the texture to it
material = materials.add("Test Material")
material.texture = full_name

# Assign the new material to our face we created
face.material = material

# Set the projection of the applied material
face.set_texture_projection(face.normal, true)

# Get the projection of the applied material
vector = face.get_texture_projection(true)

See Also:

Version:

  • SketchUp 2014



393
394
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 393

def get_texture_projection(frontside)
end

#get_UVHelper(front = true, back = true) ⇒ Sketchup::UVHelper #get_UVHelper(front = true, back = true, texturewriter) ⇒ Sketchup::UVHelper

The get_UVHelper object is used to retrieve a UVHelper object for use in texture manipulation on a face.

Examples:

model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [9, 0, 0]
pts[2] = [9, 9, 0]
pts[3] = [0, 9, 0]

# Add the face to the entities in the model
face = entities.add_face(pts)
tw = Sketchup.create_texture_writer
uvHelp = face.get_UVHelper(true, true, tw)

Overloads:

  • #get_UVHelper(front = true, back = true) ⇒ Sketchup::UVHelper

    True if you want the texture coordinates for the front face, false if not.

    True if you want the texture coordinates for the back face, false if not.

  • #get_UVHelper(front = true, back = true, texturewriter) ⇒ Sketchup::UVHelper

    True if you want the texture coordinates for the front face, false if not.

    True if you want the texture coordinates for the back face, false if not.

    An optional TextureWriter object.

Version:

  • SketchUp 6.0



322
323
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 322

def get_UVHelper(*args)
end

#loopsArray<Sketchup::Loop>

The loops method is used to get an array of all of the loops that bound the face.

Examples:

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)
loops = face.loops

Version:

  • SketchUp 6.0



417
418
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 417

def loops
end

#materialSketchup::Material?

The material method is used to retrieve the material assigned to the front of the face. (This method is inherited from the Drawingelement parent class.)

Examples:

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)

# Add a material to the face, then check to see that it was added
face.material = "red"
material = face.material

Version:

  • SketchUp 6.0



446
447
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 446

def material
end

#material=(material) ⇒ Sketchup::Material

The material= method is used to set the material assigned to the front side of the face. (This method is inherited from the Drawingelement parent class.)

Examples:

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)
status = face.material = "red"

Version:

  • SketchUp 6.0



474
475
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 474

def material=(material)
end

#mesh(flags = 0) ⇒ Geom::PolygonMesh

The mesh method creates a polygon mesh that represents the face. See the Geom::PolygonMesh class for more information.

Valid flags are:

  • 0: Include PolygonMeshPoints,

  • 1: Include PolygonMeshUVQFront,

  • 2: Include PolygonMeshUVQBack,

  • 4: Include PolygonMeshNormals.

Use bitwise OR to combine flags. A value of 7 will include all flags, for example.

Examples:

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)

kPoints = 0
kUVQFront = 1
kUVQBack = 2
kNormals = 4
flags = kPoints | kUVQFront | kUVQBack | kNormals # equals to 7
mesh = face.mesh(flags)

Version:

  • SketchUp 6.0



517
518
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 517

def mesh(flags = 0)
end

#normalGeom::Vector3d

The normal method is used to retrieve the 3D vector normal to the face in the front direction.

Examples:

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)
normal = face.normal

Version:

  • SketchUp 6.0



541
542
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 541

def normal
end

#outer_loopSketchup::Loop

This method is used to retrieve the outer loop that bounds the face.

Examples:

# Create a series of points that define a new face.
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [9, 0, 0]
pts[2] = [9, 9, 0]
pts[3] = [0, 9, 0]

# Add the face to the entities in the model
face = entities.add_face(pts)
loop = face.outer_loop

Version:

  • SketchUp 6.0



564
565
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 564

def outer_loop
end

#planeArray(Float, Float, Float, Float)

The plane method is used to retrieve the plane of the face. See the Array class for information on how planes are stored.

Examples:

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)
plane = face.plane

Version:

  • SketchUp 6.0



588
589
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 588

def plane
end

#position_material(material, points, on_front) ⇒ Sketchup::Face, false #position_material(material, points, on_front, projection) ⇒ Sketchup::Face, false

The #position_material method is used to position a material on a face.

The points argument must contain 2, 4, 6 or 8 points. The points are used in pairs to describe where a point in the texture image is positioned on the Face. The first point in each pair is a 3D point in the model. The second point in each pair of points is a 2D point that gives the (u,v) coordinates of a point in the image to match up with the 3D point.

Examples:

model = Sketchup.active_model
entities = model.active_entities

# Create a face and add it to the model entities
points = [
  Geom::Point3d.new(0, 0, 1),
  Geom::Point3d.new(9, 0, 1),
  Geom::Point3d.new(9, 9, 1),
  Geom::Point3d.new(0, 9, 1),
]
face = entities.add_face(points)

# Export an image to use as a texture
path = Sketchup.temp_dir
full_name = File.join(path, "temp_image.jpg")
model.active_view.write_image(full_name, 500, 500, false, 0.0)

# Create a material and assign the texture to it
material = model.materials.add("Test Material")
material.texture = full_name

# Assign the new material to our face we created
face.material = material

mapping = [
  Geom::Point3d.new(3,0,0), # Model coordinate
  Geom::Point3d.new(0,0,0), # UV coordinate
]
on_front = true
face.position_material(material, mapping, on_front)

Overloads:

  • #position_material(material, points, on_front) ⇒ Sketchup::Face, false

    This variant positions a material on the face’s plane without projection.

  • #position_material(material, points, on_front, projection) ⇒ Sketchup::Face, false

    This variant positions a material on the face’s plane with projection.

Raises:

  • ArgumentError if the provided points are not in the size of 2, 4, 6 or 8.

  • ArgumentError if the provided points could not be computed to a valid UV mapping.

See Also:

Version:

  • SketchUp 6.0



681
682
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 681

def position_material(*args)
end

#pushpull(distance, copy = false) ⇒ nil

The pushpull method is used to perform a push/pull on a face.

The distance is measured in the direction that the face normal is pointing.

Examples:

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)
status = face.pushpull(100, true)

Version:

  • SketchUp 6.0



713
714
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 713

def pushpull(distance, copy = false)
end

#reverse!Sketchup::Face, false

The reverse! method is used to reverse the face’s orientation, meaning the front becomes the back.

Examples:

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)
status = face.reverse!

Version:

  • SketchUp 6.0



737
738
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 737

def reverse!
end

#set_texture_projection(vector, frontside) ⇒ Boolean

Deprecated.

This function never worked correctly. It’s not capable of controlling the position and orientation of the texture. In some cases it produced an invalid model. After SketchUp 2021.1 the method will raise NotImplementedError.

The #set_texture_projection method is used to set the texture projection direction.

See Also:

Version:

  • SketchUp 2014



762
763
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 762

def set_texture_projection(vector, frontside)
end

#texture_positioned?(front) ⇒ Boolean

The #texture_positioned? method is used to check if the face has a texture that is positioned.

A texture is positioned when it’s not using the default texture coordinates.

When a user uses the Paint Bucket Tool to apply a material sampled from the Material Browser it will use default texture coordinates and not be positioned. It will be positioned if the user uses the Position Texture Tool.

When an API user uses Drawinglement#material= the texture is not positioned. It will be positioned when the API user uses #position_material. It it also positioned of the face was crafted via Geom::PolygonMesh.

Examples:

model = Sketchup.active_model
entities = model.active_entities
faces = entities.grep(Sketchup::Face).select { |face|
  face.texture_positioned?(true) || face.texture_positioned?(false)
}

See Also:

Version:

  • SketchUp 2021.1



799
800
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 799

def texture_positioned?(front)
end

#texture_projected?(front) ⇒ Boolean

The #texture_projected? method is used to check if the face has a texture that is projected.

A texture is projected when the user enables this property via the Position Texture Tool.

It is also projected when the API user passes a projection vector to #position_material.



824
825
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 824

def texture_projected?(front)
end

#uv_tile_at(position, front) ⇒ Array<Geom::Point3d>?

The #uv_tile_at method is used to get the corner positions (model and UV) of a UV tile.

The UV tile bounds the given reference point on the plane of the face. If the reference isn’t on the plane of the face it will be projected onto it.

The world coordinates are on the plane of the face unless the texture is projected. When the texture is projected the the world points are on an arbitrary plane that is perpendicular to the projection direction.

The returned coordinates are arranged to be compatible with #position_material.

Getting the bounds of the UV tile under the cursor:

The red quadrilateral represents the model points returned.

Examples:

Copy material from front to back

model = Sketchup.active_model
model.active_entities.grep(Sketchup::Face) { |face|
  material = face.material

  if material&.texture.nil?
    face.back_material = material
  end

  reference = face.vertices.first.position
  mapping = face.uv_tile_at(reference, true)
  if face.texture_projected?(true)
    projection = face.get_texture_projection(true)
    face.position_material(material, mapping, false, projection)
  else
    face.position_material(material, mapping, false)
  end
}

Iterate each set of world and UV coordinates

model = Sketchup.active_model
faces = model.active_entities.grep(Sketchup::Face)
face = faces.find { |face| face.material&.texture }
reference = face.vertices.first.position
mapping = face.uv_tile_at(reference, true)
mapping.each_slice(2) { |position, uv|
  puts "World: #{position.inspect} - UV: #{uv.inspect}"
}

See Also:

Version:

  • SketchUp 2021.1



890
891
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 890

def uv_tile_at(position, front)
end

#verticesArray<Sketchup::Vertex>

The vertices method is used to get an array of all of the vertices that bound the face.

Examples:

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)
vertices = face.vertices

Version:

  • SketchUp 6.0



914
915
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 914

def vertices
end