CadQuery / cadquery

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

Support eachpoint with `cq.Shape` and `cq.Workplane` in addition to callbacks #1395

Open adam-urbanczyk opened 10 months ago

adam-urbanczyk commented 10 months ago

E.g.

b = cq.Workplane().box(2,2,2)
s = cq.Workplane().sphere(0.5)

res = b.faces().eachpoint(s)
dov commented 2 months ago

@adam-urbanczyk In continuation of your comment on #1574 , I would add cq.Wire in addition to cq.Shape and cq.Workplane to this issue.

adam-urbanczyk commented 2 months ago

cq.Wire is a cq.Shape

dov commented 2 months ago

@adam-urbanczyk I got it working for a Shape by renaming the argument arg and dispatching on its type. However I need some guidance about what semantics you expect for a Workspace. Just moving the workspace by the following lambda obviously does not work:

        if isinstance(arg, Workplane):
            wp = arg
            callback = lambda v : wp.move(v)
adam-urbanczyk commented 2 months ago

Something like this:

v.moved(loc) for v in arg.vals() if isinstance(v, Shape)
dov commented 2 months ago

Something like this:

v.moved(loc) for v in arg.vals() if isinstance(v, Shape)

Thanks @adam-urbanczyk . In my PR I used the following. Let me know this is what you intended.

res = [
    v.moved(p).move(loc)
    for v in arg.vals()
    for p in pnts
    if isinstance(v, Shape)
]