CadQuery / cadquery

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

Conditional methods #1537

Closed aavogt closed 3 months ago

aavogt commented 3 months ago

1536 suggests a Workplane.when() or similar conditionals such as unless and ifte.

from fn import _
cq.Workplane.when = lambda self, cond, f: cond and f(self) or self
cq.Workplane().box(5,5,5).when(True, _.faces(">Y").workplane().hole(1)) # pretty but `_` needs fixing
cq.Workplane().box(5,5,5).when(True, lambda c: c.faces(">Y").workplane().hole(1)) # longer but it works

fn.py's doesn't deal with methods the same way it deals with other attributes. I'm not sure if it can be fixed. Would an `` that records/evaluates only the methods defined in cq might be worth doing?

adam-urbanczyk commented 3 months ago

Just use normal control flow statements.