ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Face

Overview

A planar polygon. Access its front material through the inherited ModraUp::Drawingelement#material and ModraUp::Drawingelement#material= methods. Use ModraUp::Face#back_material and ModraUp::Face#back_material= for the back.

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0])
face.normal
face.pushpull(1)

Constants # collapse

ModraUp::Face::PointUnknown

Face#classify_point cannot be determined.

ModraUp::Face::PointInside

Point inside the face (not on an edge or vertex).

ModraUp::Face::PointOnVertex

The point lies on a face vertex.

ModraUp::Face::PointOnEdge

The point lies on the edge of the face.

ModraUp::Face::PointOnFace

Point on Face (preserve constant; current category is PointInside / boundary constant).

ModraUp::Face::PointOutside

Point lies on the face plane but is outside (including within holes).

ModraUp::Face::PointNotOnPlane

The point is not on the plane of the face.

Instance Method Summary # collapse

Inherited from ModraUp::Drawingelement

Inherited from ModraUp::Entity

Instance Method Details

face.pushpull(distance, copy = false) ⇒ nil

Push-pull along the face normal. The isolated face remains in the starting plane; the default push-pull moves the vertices of the solid surface, and copy set to true retains the starting face.

Parameters:

  • distance (Numeric)
  • copy (Boolean)

Returns:

  • (nil)

Raises:

  • [RuntimeError] The face has been deleted.

Examples:

face = ModraUp.active_model.entities.add_face([0,0,0], [10,0,0], [10,10,0], [0,10,0])
face.pushpull(10)

face.material ⇒ ModraUp::Material, nil

Front material. Inherits from Drawingelement#material. Back face material is seen at Face#back_material.

Returns:

  • (ModraUp::Material, nil)

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
face.material = "red"
face.material

face.material=(material) ⇒ material

Set the face material. Inherited from Drawingelement#material=. nil clears the material. No need to open the group/component.

Parameters:

  • material (ModraUp::Material, String, ModraUp::Color, nil)

Returns:

  • (ModraUp::Material, String, ModraUp::Color, nil)

Raises:

  • [TypeError] Not a material, color, or name
  • [ArgumentError] Unknown material name

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
face.material = "red"
face.material = nil

face.back_material ⇒ ModraUp::Material, nil

Back material. Only ModraUp::Face has this method. If not assigned, it is nil.

Returns:

  • (ModraUp::Material, nil)

Raises:

  • [RuntimeError] The face has been deleted.

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
face.back_material = "red"
face.back_material

face.back_material=(material) ⇒ material

Sets the back material. Only ModraUp::Face has this method. nil clears it. No need to open the group/component.

Parameters:

  • material (ModraUp::Material, String, ModraUp::Color, nil)

Returns:

  • (ModraUp::Material, String, ModraUp::Color, nil)

Raises:

  • [TypeError] Not a material, color, or name
  • [ArgumentError] Unknown material name
  • [RuntimeError] The face has been deleted or locked.

Examples:

grp = ModraUp.active_model.entities.add_group
face = grp.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
face.back_material = "red"
face.back_material = nil

face.all_connected ⇒ Array

Returns the faces and edges connected by edges to this face, including the face itself.

Returns:

  • (Array<ModraUp::Face, ModraUp::Edge>)

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
face.all_connected.length >= 5

face.area ⇒ Floatface.area(transform) ⇒ Float

Area (in square inches). An optional transformation can be used to calculate the scaled 'visual' area.

Parameters:

  • transform (Geom::Transformation)

Returns:

  • (Float)

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0])
face.area  #=> 4.0

face.classify_point(point) ⇒ Integer

Determine the position of the point relative to the face. Compare it with constants like PointInside instead of hardcoding integers.

Parameters:

  • point (Geom::Point3d)

Returns:

  • (Integer)

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0])
face.classify_point([1, 1, 0]) == ModraUp::Face::PointInside

face.coplanar_with?(other_face) ⇒ Boolean

Whether two faces are coplanar.

Parameters:

  • other_face (ModraUp::Face)

Returns:

  • (Boolean)

Examples:

a = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
a.coplanar_with?(a)

face.edges ⇒ Array<ModraUp::Edge>

Edges surrounding the face (outer ring followed by inner rings, with duplicates removed).

Returns:

  • (Array<ModraUp::Edge>)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).edges.length
  #=> 4

face.followme(edges) ⇒ Booleanface.followme(edge) ⇒ Boolean

Section plane sweeps along the edge chain. Failure does not modify the model.

Parameters:

  • edges (Array<ModraUp::Edge>, ModraUp::Edge)

Returns:

  • (Boolean)

Examples:

ents = ModraUp.active_model.entities
profile = ents.add_face([0, 0, 0], [1, 0, 0], [1, 0, 1], [0, 0, 1])
path = ents.add_line([0, 0, 0], [0, 4, 0])
profile.followme(path)

face.loops ⇒ Array<ModraUp::Loop>

The outer loop comes first, followed by the holes.

Returns:

  • (Array<ModraUp::Loop>)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).loops.length
  #=> 1

face.normal ⇒ Geom::Vector3d

Normal to the face.

Returns:

  • (Geom::Vector3d)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).normal.parallel?(Z_AXIS)

face.outer_loop ⇒ ModraUp::Loop

Outer loop.

Returns:

  • (ModraUp::Loop)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).outer_loop.outer?

face.plane ⇒ Array

Plane [A, B, C, D] (Ax + By + Cz + D = 0).

Returns:

  • (Array<Float>)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).plane.length
  #=> 4

face.reverse! ⇒ ModraUp::Face, false

Flip the face. Go through a model transaction.

Returns:

  • (ModraUp::Face, false)

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0])
n = face.normal
face.reverse!
face.normal.samedirection?(n.reverse)

face.vertices ⇒ Array<ModraUp::Vertex>

Vertices surrounding the face (outer ring followed by inner rings, with duplicates removed).

Returns:

  • (Array<ModraUp::Vertex>)

Examples:

ModraUp.active_model.entities.add_face([0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]).vertices.length
  #=> 4

face.mesh ⇒ Geom::PolygonMeshface.mesh(flags) ⇒ Geom::PolygonMesh

Triangulate the face into a mesh. flags can be bitwise combined: 1 front UVQ, 2 back UVQ, 4 normal. Omitting flags results in points and triangles; hidden edge point numbers are negative.

Parameters:

  • flags (Integer) Default 0

Returns:

  • (Geom::PolygonMesh)

Raises:

  • [RuntimeError] The face has been deleted.

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0])
mesh = face.mesh
mesh.is_a?(Geom::PolygonMesh) && mesh.count_polygons >= 1

face.get_UVHelper ⇒ ModraUp::UVHelperface.get_UVHelper(front, back) ⇒ ModraUp::UVHelperface.get_UVHelper(front, back, texture_writer) ⇒ ModraUp::UVHelper

Returns the helper object for the current UV transformation of the face. When the face has been ModraUp::TextureWriter#loaded by a ModraUp::TextureWriter, it uses the cached UVs (consistent with the viewport tessellation).

Parameters:

  • front (Boolean) Default true
  • back (Boolean) Default true
  • texture_writer (ModraUp::TextureWriter)

Returns:

  • (ModraUp::UVHelper)

Raises:

  • [RuntimeError] The face has been deleted.

Examples:

face = ModraUp.active_model.entities.add_face([0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0])
face.get_UVHelper.get_front_UVQ([0, 0, 0])

face.position_material(material, points, front) ⇒ ModraUp::Face, falseface.position_material(material, points, front, projection) ⇒ ModraUp::Face, false

Pins the material using world and UV point pairs. Supply 2, 4, 6, or 8 Geom::Point3d values in points, alternating between world and UV coordinates.

Parameters:

  • material (ModraUp::Material, nil)
  • points (Array<Geom::Point3d, Array<Numeric>>)
  • front (Boolean)
  • projection (Geom::Vector3d) Optional projection direction

Returns:

  • (ModraUp::Face, false) Returns the face if successful; returns false if there is no texture.

Raises:

  • [TypeError] The input is not a ModraUp::Material or the points are not an Array.
  • [ArgumentError] Incorrect number of points or unable to determine valid mapping
  • [RuntimeError] The face has been deleted.

Examples:

model = ModraUp.active_model
face = model.entities.add_face([0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0])
mat = model.materials.add("UVPin")
face.position_material(mat, [[0, 0, 0], [0, 0, 0], [2, 0, 0], [1, 0, 0], [0, 2, 0], [0, 1, 0]], true)

face.clear_texture_position(front) ⇒ nil

Clear the texture position and projection for the specified face, restoring the default texture position.

Parameters:

  • front (Boolean)

Returns:

  • (nil)

face.clear_texture_projection(front) ⇒ nil

Clears the projection flag and retains the texture positioning.

Parameters:

  • front (Boolean)

Returns:

  • (nil)

face.get_texture_projection(front) ⇒ Geom::Vector3d, nil

Returns the texture projection direction; returns nil if there is no texture projection.

Parameters:

  • front (Boolean)

Returns:

  • (Geom::Vector3d, nil)

face.texture_projected?(front) ⇒ Boolean

Returns whether the specified face has a projected texture.

Parameters:

  • front (Boolean)

Returns:

  • (Boolean)

face.texture_positioned?(front) ⇒ Boolean

Determines whether the texture on the specified face is explicitly positioned.

Parameters:

  • front (Boolean)

Returns:

  • (Boolean)

face.set_texture_projection(vector, front)

This deprecated interface throws NotImplementedError starting with SketchUp 2021.1; please use the projection parameter of the position_material method.

Parameters:

  • vector (Geom::Vector3d)
  • front (Boolean)

Returns:

  • (Object)

face.get_glued_instances ⇒ Array<ModraUp::ComponentInstance, ModraUp::Group>

Returns the instances and groups glued to this face in the same drawing context.

Returns:

  • (Array<ModraUp::ComponentInstance, ModraUp::Group>)

face.uv_tile_at(position, front) ⇒ Array<Geom::Point3d>, nil

Returns the four corners of the texture brick surrounding the reference point, alternately in model points and UV points, which can be used for position_material; returns nil if there is no texture.

Parameters:

  • position (Geom::Point3d)
  • front (Boolean)

Returns:

  • (Array<Geom::Point3d>, nil)