CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.15k stars 289 forks source link

Use face as sketch for cut/ thicken operation #1519

Closed GaN-T closed 1 month ago

GaN-T commented 7 months ago

Hi all,

Is it possible to use an existing face as a mask to perform operations on the created objects in cadquery?

slab =  cq.Workplane("front").box(5,5,2)
slab_posts = b.faces(">Z").workplane().rect(3,3, forConstruction = True).vertices().circle(0.5).extrude(2)
posts.faces(">Z").extrude(-1)   #  <<<<<<< This line doesn't work and produces an error

In the simple example above, I would like to use the top face (the four circles) as a sketch to then extrude back down into the original object (slab_posts) to a given depth. How do I use the face geometry for further operations? In FreeCAD, we can use "project" to inherit features into a sketch to then perform a given operation. Is there a way to do something like this in Cadquery?

lorenzncode commented 7 months ago

The edges can be projected to the slab, then added to the pending edges for extrude/cut.

import cadquery as cq

slab = cq.Workplane().box(5, 5, 2)

posts = (
    slab.faces(">Z")
    .workplane()
    .rect(3, 3, forConstruction=True)
    .vertices()
    .circle(0.5)
    .extrude(2, combine=False)
)

slab = slab.faces(">Z").tag("top")

edges = [
    e.project(slab.faces(tag="top").val(), (0, 0, -1)) for e in posts.edges(">Z").vals()
]

slab = slab.workplaneFromTagged("top").add(edges).toPending()
slab = slab.extrude(-1, "s")

With changes for #1511, perhaps instead the post faces could be added to a sketch placed on the slab face for the cut.