cadquery
Sketch
Workplane
Assembly

Sketch.finalize()

The Sketch.finalize() method is a useful tool in the CAD/CAM programming language, CadQuery. It helps to finalize and prepare the sketch for extrusion or other types of operations, ultimately leading to the creation of a solid 3D model.

Syntax

Sketch.finalize()

Parameters

The Sketch.finalize() method takes no parameters.

Return Value

The Sketch.finalize() method returns nothing. Instead, it modifies the sketch in place.

Description

Sketch.finalize() is called at the end of the sketching process when all entities, constraints, and dimensions have been defined. Its purpose is to clean and prepare the sketch for further use, such as extruding, sweeping, or revolving the sketch.

The Sketch.finalize() method performs the following actions:

  1. It removes redundant or unnecessary entities: The method searches for and removes any duplicate or redundant entities, such as overlapping lines or arcs.

  2. It performs automatic construction of entities: Sketch.finalize() creates missing points or lines where it is obvious what should be connected.

  3. It validates the constraints: Sketch.finalize() ensures that all the constraints are valid and that no contradiction arises due to over-constrained or under-constrained geometry.

  4. It removes temporary objects: Sketch.finalize() deletes any temporary objects used during the creation of the sketch that are no longer necessary.

Examples

import cadquery as cq

# Create a sketch
sketch = cq.Workplane().rect(10, 5).extrude(2)

# Finalize the sketch to prepare it for extrusion
sketch = sketch.val().Sketch.finalize()

In this example, we create a basic rectangle shape and extrude it by a value of 2. Before extruding, we finalize the sketch by calling the Sketch.finalize() method. This ensures that the sketch is free of duplicates and inconsistencies that might cause problems during extrusion.

Conclusion

The Sketch.finalize() method is essential in preparing a sketch for further use in CAD/CAM programming. By validating constraints, removing redundant entities and temporary objects, and automatically constructing missing lines or points, Sketch.finalize() ensures that the sketch is clean and ready for any operation that may follow.