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

Returns:

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:

  • #areaFloat

    Returns the area of the face in square inches.

    Returns:

    • (Float)

      the area of the face in square inches.

  • #area(transform) ⇒ Float

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

    Parameters:

    Returns:

    • (Float)

      the area of the face in square inches.

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

Returns:

  • (Sketchup::Material, nil)

    a Material object representing the material on the back of the face (if successful)

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"

Parameters:

Returns:

  • (Sketchup::Material)

    the name of the valid material or the new Material object (if successful)

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

Parameters:

Returns:

  • (Integer)

    an integer describing where a Point3d is in relation to the referenced Face.

Version:

  • SketchUp 6.0



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

def classify_point(point)
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

Returns:

Version:

  • SketchUp 6.0



222
223
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 222

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)

Overloads:

  • #followme(edges) ⇒ Boolean

    Parameters:

    Returns:

    • (Boolean)
  • #followme(edge) ⇒ Boolean

    Parameters:

    Returns:

    • (Boolean)

Version:

  • SketchUp 6.0



261
262
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 261

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

Returns:

Version:

  • SketchUp 7.0 M1



331
332
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 331

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)

Parameters:

  • frontside (Boolean)

    true for front side, false for back side.

Returns:

Version:

  • SketchUp 2014



373
374
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 373

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.

    Parameters:

    • front (Boolean) (defaults to: true)
    • back (Boolean) (defaults to: true)
  • #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.

    Parameters:

Returns:

Version:

  • SketchUp 6.0



307
308
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 307

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

Returns:

Version:

  • SketchUp 6.0



397
398
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 397

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

Returns:

  • (Sketchup::Material, nil)

    a Material object representing the material on the front of the face (if successful)

Version:

  • SketchUp 6.0



426
427
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 426

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"

Parameters:

Returns:

  • (Sketchup::Material)

    the name of the valid material or the new Material object (if successful)

Version:

  • SketchUp 6.0



454
455
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 454

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)

Parameters:

  • flags (Integer) (defaults to: 0)

    One or more flags used to generate a mesh.

Returns:

Version:

  • SketchUp 6.0



497
498
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 497

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

Returns:

Version:

  • SketchUp 6.0



521
522
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 521

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

Returns:

  • (Sketchup::Loop)

    a Loop object representing the outer loop (if successful)

Version:

  • SketchUp 6.0



544
545
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 544

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

Returns:

  • (Array(Float, Float, Float, Float))

    a plane that contains the face (if successful)

Version:

  • SketchUp 6.0



568
569
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 568

def plane
end

#position_material(material, pt_array, o_front) ⇒ Sketchup::Face, false

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

The pt_array must contain 2, 4, 6 or 8 points. The points are used in pairs to tell 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. It should be a point on the Face. 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
pts = []
pts[0] = [0, 0, 1]
pts[1] = [9, 0, 1]
pts[2] = [9, 9, 1]
pts[3] = [0, 9, 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 = model.materials.add("Test Material")
material.texture = full_name

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

pt_array = []
pt_array[0] = Geom::Point3d.new(3,0,0)
pt_array[1] = Geom::Point3d.new(0,0,0)
on_front = true
face.position_material(material, pt_array, on_front)

Parameters:

  • material (Sketchup::Material)

    a Material object.

  • pt_array (Array<Geom::Point3d>)

    An array of Point3d objects used to position the material.

  • o_front (Boolean)

    true to position the texture on the front of the Face or false to position it on the back of the Face.

Returns:

  • (Sketchup::Face, false)

    the face upon success, false upon failure.

Version:

  • SketchUp 6.0



622
623
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 622

def position_material(material, pt_array, o_front)
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)

Parameters:

  • distance (Length)

    The distance to push/pull the face.

  • copy (Boolean) (defaults to: false)

    Create a new push/pull starting face if true (equivalent of pressing CTRL while in SketchUp), do not create a push/pull starting face if false.

Returns:

  • (nil)

Version:

  • SketchUp 6.0



654
655
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 654

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!

Returns:

  • (Sketchup::Face, false)

    the reversed Face object if successful, false if unsuccessful

Version:

  • SketchUp 6.0



678
679
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 678

def reverse!
end

#set_texture_projection(vector, frontside) ⇒ Boolean

Deprecated.

This function never worked right. It’s not possible to control the position and orientation of the texture.

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

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 testure to it.
material = materials.add("Test Material")
material.texture = full_name

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

# Returns nil if not successful, path if successful
result = face.set_texture_projection(face.normal, true)

Parameters:

  • vector (Geom::Vector3d)

    representing the direction of the projection. Use nil to remove the projection.

  • frontside (Boolean)

    true for front side, false for back side.

Returns:

  • (Boolean)

    true on success

Version:

  • SketchUp 2014



724
725
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 724

def set_texture_projection(vector, frontside)
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

Returns:

Version:

  • SketchUp 6.0



748
749
# File 'lib/sketchup-api-stubs/stubs/Sketchup/Face.rb', line 748

def vertices
end