From f688133bfb990628a95f53ed32a76b5322478d60 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Thu, 16 Jul 2026 21:07:51 +0200 Subject: [PATCH 1/3] Better imprint for assy --- cadquery/occ_impl/assembly.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/cadquery/occ_impl/assembly.py b/cadquery/occ_impl/assembly.py index d2485e612..8fabd162b 100644 --- a/cadquery/occ_impl/assembly.py +++ b/cadquery/occ_impl/assembly.py @@ -37,7 +37,7 @@ ) from OCP.BRepAlgoAPI import BRepAlgoAPI_Fuse from OCP.TopTools import TopTools_ListOfShape -from OCP.BOPAlgo import BOPAlgo_GlueEnum, BOPAlgo_MakeConnected +from OCP.BOPAlgo import BOPAlgo_GlueEnum, BOPAlgo_Builder from OCP.TopoDS import TopoDS_Shape from OCP.gp import gp_EulerSequence @@ -49,7 +49,7 @@ ) from .geom import Location -from .shapes import Shape, Solid, Compound +from .shapes import Shape, Solid, Compound, GlueLiteral, _set_glue, _set_builder_options from .exporters.vtk import toString, extractEdgesFaces from ..cq import Workplane from ..utils import BiDict @@ -855,7 +855,9 @@ def toFusedCAF( return top_level_lbl, doc -def imprint(assy: AssemblyProtocol) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: +def imprint( + assy: AssemblyProtocol, tol: float = 0.0, glue: GlueLiteral = "full", +) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: """ Imprint all the solids and construct a dictionary mapping imprinted solids to names from the input assy. """ @@ -868,22 +870,28 @@ def imprint(assy: AssemblyProtocol) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]] id_map[s] = name # connect topologically - bldr = BOPAlgo_MakeConnected() - bldr.SetRunParallel(True) - bldr.SetUseOBB(True) + builder = BOPAlgo_Builder() + + _set_glue(builder, glue) + _set_builder_options(builder, tol) for obj in id_map: - bldr.AddArgument(obj.wrapped) + builder.AddArgument(obj.wrapped) - bldr.Perform() - res = Shape(bldr.Shape()) + builder.Perform() + res = Shape(builder.Shape()) # make the connected solid -> id map + ocp_origins = builder.Origins() origins: Dict[Shape, Tuple[str, ...]] = {} for s in res.Solids(): - ids = tuple(id_map[Solid(el)] for el in bldr.GetOrigins(s.wrapped)) - # if GetOrigins yields nothing, solid was not modified + if ocp_origins.IsBound(s.wrapped): + # if GetOrigins yields nothing, solid was not modified + ids = tuple(id_map[Solid(el)] for el in ocp_origins.Find(s.wrapped)) + else: + ids = () + origins[s] = ids if ids else (id_map[s],) return res, origins From a4acc30c190525614c1ecfcd6c6d5944c1c18532 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Fri, 17 Jul 2026 11:26:38 +0200 Subject: [PATCH 2/3] Typing fix --- cadquery/occ_impl/nurbs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadquery/occ_impl/nurbs.py b/cadquery/occ_impl/nurbs.py index 4a958d35f..9f77b1949 100644 --- a/cadquery/occ_impl/nurbs.py +++ b/cadquery/occ_impl/nurbs.py @@ -357,7 +357,7 @@ def isoline(self, param: float, dir: Literal["u", "v"] = "u") -> Curve: @njiti def _preprocess( u: Array, order: int, knots: Array, periodic: bool -) -> Tuple[Array, Array, Optional[int], Optional[int], int]: +) -> Tuple[Array, Array, int, int, int]: """ Helper for handling periodicity. This function extends the knot vector, wraps the parameters and calculates the delta span. From bd53fc8d6bb971f40ac0ebf9699f514f15d0ec44 Mon Sep 17 00:00:00 2001 From: adam-urbanczyk <13981538+adam-urbanczyk@users.noreply.github.com> Date: Fri, 17 Jul 2026 15:17:19 +0200 Subject: [PATCH 3/3] Add a note about glue and threads. --- cadquery/occ_impl/assembly.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cadquery/occ_impl/assembly.py b/cadquery/occ_impl/assembly.py index 8fabd162b..eb22cc811 100644 --- a/cadquery/occ_impl/assembly.py +++ b/cadquery/occ_impl/assembly.py @@ -860,6 +860,9 @@ def imprint( ) -> Tuple[Shape, Dict[Shape, Tuple[str, ...]]]: """ Imprint all the solids and construct a dictionary mapping imprinted solids to names from the input assy. + + Depending on the use case, it might be required do use different `glue` option. Moreover, for large models + it might be needed to limit the number of threads using :meth:`cadquery.func.setThreads` """ # make the id map