gumyr / cq_warehouse

A cadquery parametric part collection
Apache License 2.0
107 stars 23 forks source link

`Face.embossToShape(...` is failing with RuntimeError: Error building non-planar face with provided surfacePoints #41

Open greyltc opened 2 years ago

greyltc commented 2 years ago
$ ipython
Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import cadquery as cq
   ...: import cq_warehouse.extensions
   ...: 
   ...: plate_size = (50, 50, 5)
   ...: plate = cq.Workplane("XY").box(*plate_size, centered=(True, True, False))
   ...: tplane = plate.faces(">Z").workplane().plane
   ...: faced = cq.Face.makeFromWires(cq.Workplane("XY").rect(30,2).wires().val())
   ...: emb = faced.embossToShape(targetObject=plate.val(),surfacePoint=tplane.origin, surfaceXDirection=tplane.xDir)
---------------------------------------------------------------------------
StdFail_NotDone                           Traceback (most recent call last)
File /usr/lib/python3.10/site-packages/cq_warehouse/extensions.py:1689, in makeNonPlanarFace(exterior, surfacePoints, interiorWires)
   1688     surface.Build()
-> 1689     surface_face = Face(surface.Shape())
   1690 except StdFail_NotDone as e:

StdFail_NotDone: BRep_API: command not done

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Input In [1], in <cell line: 8>()
      6 tplane = plate.faces(">Z").workplane().plane
      7 faced = cq.Face.makeFromWires(cq.Workplane("XY").rect(30,2).wires().val())
----> 8 emb = faced.embossToShape(targetObject=plate.val(),surfacePoint=tplane.origin, surfaceXDirection=tplane.xDir)

File /usr/lib/python3.10/site-packages/cq_warehouse/extensions.py:1525, in _face_embossToShape(self, targetObject, surfacePoint, surfaceXDirection, internalFacePoints, tolerance)
   1520     embossed_surface_points = [
   1521         Vector(*v.toTuple()) for v in embossed_grid.Vertices()
   1522     ]
   1524 # Phase 4 - Build the faces
-> 1525 embossed_face = embossed_outer_wire.makeNonPlanarFace(
   1526     surfacePoints=embossed_surface_points, interiorWires=embossed_inner_wires
   1527 )
   1529 return embossed_face

File /usr/lib/python3.10/site-packages/cq_warehouse/extensions.py:1739, in _wire_makeNonPlanarFace(self, surfacePoints, interiorWires)
   1714 def _wire_makeNonPlanarFace(
   1715     self,
   1716     surfacePoints: list["Vector"] = None,
   1717     interiorWires: list["Wire"] = None,
   1718 ) -> "Face":
   1719     """Create Non-Planar Face with perimeter Wire
   1720 
   1721     Create a potentially non-planar face bounded by exterior Wire,
   (...)
   1737         Non planar face
   1738     """
-> 1739     return makeNonPlanarFace(self, surfacePoints, interiorWires)

File /usr/lib/python3.10/site-packages/cq_warehouse/extensions.py:1691, in makeNonPlanarFace(exterior, surfacePoints, interiorWires)
   1689         surface_face = Face(surface.Shape())
   1690     except StdFail_NotDone as e:
-> 1691         raise RuntimeError(
   1692             "Error building non-planar face with provided surfacePoints"
   1693         ) from e
   1695 # Next, add wires that define interior holes - note these wires must be entirely interior
   1696 if interiorWires:

RuntimeError: Error building non-planar face with provided surfacePoints
greyltc commented 2 years ago

In the specific example, everything is planar, so I find it a bit strange that a non-planar face code path is being followed here. Maybe the issue is with detecting if the emboss will be onto a planar or non-planar shape?