cadquery
cadquery copied to clipboard
Selecting an inner face with ">>Z[1]" raises an unhelpful `GeomAPI_ProjectPointOnSurf::LowerDistanceParameters` exception
When running the following code, cadquery raises an exception:
import cadquery as cq
test = (
cq.Workplane("XY")
.circle(10)
.extrude(20)
.faces(">Z")
.workplane()
.hole(15, 5)
.faces(">>Z[1]")
.workplane()
.hole(10, 5)
)
Exception:
Traceback (most recent call last):
File "/Users/jez/Code/test/./test.py", line 12, in <module>
.workplane()
File "/opt/homebrew/Caskroom/mambaforge/base/envs/test/lib/python3.10/site-packages/cadquery/cq.py", line 622, in workplane
normal = obj.normalAt(center)
File "/opt/homebrew/Caskroom/mambaforge/base/envs/test/lib/python3.10/site-packages/cadquery/occ_impl/shapes.py", line 2386, in normalAt
u, v = projector.LowerDistanceParameters()
OCP.Standard.Standard_Failure: GeomAPI_ProjectPointOnSurf::LowerDistanceParameters
The mistake here is that the face being selected is the curved inside face of the cylinder, which of course cannot make a workplane. The fix I needed was to use ">Z[1]" instead of ">>Z[1]", to only filter faces normal to Z. However, it took far too long to reach this conclusion because the error message is not clear.
Expected output: a more user friendly error that clearly states what the problem is. For example: FaceError: The selected face is curved, a workplane cannot be created from a curved face.
A workplane can be usually created from a curved face.