Splitting solids using arbitrary surfaces

25 views
Skip to first unread message

Ross Worrall

unread,
Jun 13, 2024, 12:23:16 PMJun 13
to CadQuery
Hello,  sorry for the noob question...

I'm new to CADQuery and would like advice. I'm looking to decompose CAD solids into composite solid geometry, which requires a method to iterate over a solid, attempt to split on all faces. If a solid split on a face created more than one body a recursive method would be used to then start again on each new solid. I hav epreviosuly used FreeCAD and BOPTools slice API to carry this out, but am trying to omve to using CADQuery.

I have implemented a basic way of doing this is CADQuery to split on planes, which uses the workplane to split a solid but I would like to extend this to higher order surfaces (cylinders, spheres etc...). 

A minimum working example which only works for planes:
# load from STP file
input = cq.importers.importStep("double_rpp.stp")

# iterate over all solids in input STP file
for solid in input.solids().all():
    for face in solid.faces().all():
        solids_split = face.workplane().split(keepBottom=True, keepTop=True).solids().all()
        if len(solids_split) == 1:
            continue
        else:
            print('sucess, split undertaken')
            break

assembly = cq.Assembly()
for solid in solids_split:
    assembly.add(solid)

display(input)
display(assembly)

I can't seem to find a way to iterate over each solids faces and use the cut tool, when I try the following I get a Null TopoDS_Shape object. I'm missing some fundamental understanding or CADQuesry objects.

Here's my broken attempt to cut on a face:

# load from STP file
input = cq.importers.importStep("double_sphere.stp")

solid_1 = input.solids().all()[0]
face_1 = solid_1.faces().all()[0]

solid_split = solid_1.cut(face_1)

display(input)
display(solid_split)

Any advice on approaches to take would be much appreciated.

Thanks,

Ross
double_rpp.stp
double_sphere.stp

Jeremy Wright

unread,
Jun 13, 2024, 6:43:08 PMJun 13
to Ross Worrall, CadQuery
You still have access to OpenCASCADE with CadQuery using OCP (our Python bindings for OCCT). There are examples in the code:


Some potentially related issues/discussions:




--
cadquery home: https://github.com/CadQuery/cadquery
post issues at https://github.com/CadQuery/cadquery/issues
run it at home at : https://github.com/CadQuery/CQ-editor
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/328d3b95-bdc3-4e36-ae2d-378f2878474bn%40googlegroups.com.

Adam Urbanczyk

unread,
Jun 14, 2024, 12:41:31 PMJun 14
to CadQuery
cq.Workplane.split has two overloads, one of them splits with arbitrary shape.  You can also use cq.Shape.split, or cq.occ_impl.shapes.split, or ca.Shape.__truediv__ ( s1 / s2 i.e. operator notation ).

Reply all
Reply to author
Forward
0 new messages