CadQuery / cadquery

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

Selecting a face defined by Sketch on plane #1597

Open lorenzncode opened 1 month ago

lorenzncode commented 1 month ago

Say I'm working with the free func API to create a sweep. I'd like to create the wire to sweep with Sketch on a given plane (here using Workplane). There is a private method to access the face. Is there a better way or could a public interface to select the face be provided?

import cadquery as cq
from cadquery.occ_impl.shapes import *

pts = [(10, 10, 0), (20, 10, 10), (30, 10, -10), (30, 0, 0)]

path = spline(pts)
plane = cq.Plane(origin=path.startPoint(), normal=path.tangentAt(0))

profile_sketch = cq.Sketch().regularPolygon(1, 3)

# free func sweep does not support multiple wires
#profile_sketch = cq.Sketch().push([(-4, 0), (4, 0)]).regularPolygon(1, 3)

wp = cq.Workplane(plane).placeSketch(profile_sketch)

# workarounds
# 1. iter
# wi = list(iter(wp.val()))[0].wires()
# 2. private _getFaces
wi = wp._getFaces()[0].wires()

sweep = sweep(wi, path, True)
adam-urbanczyk commented 1 month ago

Good point, I think we should add cq.Sketch.val() to be consistent with cq.Workplane(). Also I think sweep could be extended to lower faces to wires (and check if they are planar).