CadQuery / cadquery

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

Cutting a face with a solid #1695

Open bragostin opened 3 days ago

bragostin commented 3 days ago

Before #1672 it was possible to perform a boolean cut of a face or shell with a solid. I guess it was not by design but because the test isSolid was not returning a correct value. Now that isSolid is fixed it is not possible anymore since boolean operations require solids to work. However it is actually quite useful to be able to cut a face with a solid. For example in additive manufacturing you often have surfaces instead of solids when you need very thin walled structures : it's the laser spot diameter that will determine the thickness of the wall and the CAD is much more lightweight with surfaces.

I managed to get back the previous behaviour by modifying findSolid like shown below. Do you think it would make sense to extend boolean operations to surfaces permanently in CQ?

    def findSolid(
        self, searchStack: bool = True, searchParents: bool = True
    ) -> Union[Solid, Compound]:
        """
        Finds the first solid object in the chain, searching from the current node
        backwards through parents until one is found.

        :param searchStack: should objects on the stack be searched first?
        :param searchParents: should parents be searched?
        :raises ValueError: if no solid is found

        This function is very important for chains that are modifying a single parent object,
        most often a solid.

        Most of the time, a chain defines or selects a solid, and then modifies it using workplanes
        or other operations.

        Plugin Developers should make use of this method to find the solid that should be modified,
        if the plugin implements a unary operation, or if the operation will automatically merge its
        results with an object already on the stack.
        """

        found = self._findType((Solid,), searchStack, searchParents)

        if found is None:
             found = self._findType((Compound,), searchStack, searchParents)
        if found is None:
             found = self._findType((Face,), searchStack, searchParents)

        if found is None:
            message = "on the stack or " if searchStack else ""
            raise ValueError(
                "Cannot find a solid {}in the parent chain".format(message)
            )

        return found
adam-urbanczyk commented 19 hours ago

It still possible to do that, just not with cq.Workplane directly.