cadquery
Sketch
Workplane
Assembly

Sketch.edges()

The Sketch.edges() method is used to extract edges from a 2D sketch in CadQuery. The edges can then be used for further operations, such as creating 3D geometries from the sketch.

Syntax

Sketch.edges([filter])

Parameters

  • filter (optional) - A function that is used to filter the edges based on certain criteria. The function takes an edge as input and returns a boolean value indicating whether the edge should be included in the result or not.

Return Value

The Sketch.edges() method returns a list of Edge objects.

Examples

Example 1

In this example, we create a simple square sketch and extract the edges from it.

import cadquery as cq

# Create a square sketch
sketch = cq.Workplane("XY").rect(1, 1)

# Extract the edges from the sketch
edges = sketch.edges()

# Print the edges
for edge in edges:
    print(edge)

Output:

Edge (  Point (-0.5,-0.5,0.0), Point (-0.5,0.5,0.0) )
Edge (  Point (0.5,-0.5,0.0), Point (-0.5,-0.5,0.0) )
Edge (  Point (-0.5,0.5,0.0), Point (0.5,0.5,0.0) )
Edge (  Point (0.5,0.5,0.0), Point (0.5,-0.5,0.0) )

Example 2

In this example, we filter the edges based on their length.

import cadquery as cq

# Create a square sketch
sketch = cq.Workplane("XY").rect(1, 1)

# Extract the edges from the sketch that are longer than 0.6 units
edges = sketch.edges(lambda e: e.length() > 0.6)

# Print the edges
for edge in edges:
    print(edge)

Output:

Edge (  Point (-0.5,-0.5,0.0), Point (-0.5,0.5,0.0) )
Edge (  Point (-0.5,0.5,0.0), Point (0.5,0.5,0.0) )
Edge (  Point (0.5,0.5,0.0), Point (0.5,-0.5,0.0) )

Notes

  • The Sketch.edges() method only extracts the outer edges of a sketch. If the sketch has holes in it, the edges of the holes will not be included in the result.
  • The edges returned by Sketch.edges() are not sorted in any particular order. If you need to process the edges in a specific order, you should sort them manually.