Example #1
0
def applyToEachFace(
    wp: cq.Workplane,
    f_workplane_selector: Callable[[cq.Face], cq.Workplane],
    f_draw: Callable[[cq.Workplane, cq.Face], cq.Workplane],
) -> cq.Workplane:
    """
    Basically equivalent to `Workplane.each(..)` but
    applicable only to faces and with tasks of face coordinate
    system selection and actually drawing in this coordinate
    system separated.

    :param wp: Workplane with some faces selected
    :param f_workplane_selector: callback that accepts
        a face and returns a Workplane (a coordinate system to
        that is passed to `f_draw`). See `XAxisInPlane`
        and `XAxisClosestTo`
    :param f_draw: a callback that accepts a workplane and
        a face and draws something in that workplane
    """
    def each_callback(face):
        wp_face = f_workplane_selector(face)

        return f_draw(wp_face, face).vals()[0]

    return wp.each(each_callback)
Example #2
0
def updatePendingWires(wp: cq.Workplane) -> cq.Workplane:
    """Fix cq bug https://github.com/CadQuery/cadquery/issues/421"""
    wp.ctx.pendingWires = []
    return wp.each(lambda shape: shape)