cadquery
Sketch
Workplane
Assembly

AreaNthSelector()

The AreaNthSelector() is a CQSelector that selects the n-th largest or smallest face in a solid or compound.

Syntax

AreaNthSelector(n: int, smallest: bool = False)

Parameters

  • n : int
    • The n-th face to select.
  • smallest : bool (default: False)
    • If True, selects the n-th smallest face instead of the largest.

Return Value

A CQSelector that selects the n-th largest or smallest face in a solid or compound.

Example

import cadquery as cq

# Create a box
box = cq.Workplane("XY").box(3, 4, 5)

# Select and color the largest 3 faces
result = box.faces(AreaNthSelector(3))
result.color("red")

# Show the result
show_object(result)

Explanation

The AreaNthSelector is used to select a face in a solid or compound based on its area. The selector takes two parameters: n and smallest. The n parameter is an integer representing the n-th largest or smallest face to select. The smallest parameter is a boolean that, if True, selects the n-th smallest face instead of the largest.

In the example above, a box is created using the box method of the Workplane class. The faces method is then used to select the largest 3 faces of the box using the AreaNthSelector with n=3. The selected faces are colored red using the color method, and the result is displayed using the show_object function.