From a1d6b1a03ffded53596c6be06c5929cddda5f723 Mon Sep 17 00:00:00 2001 From: AU Date: Thu, 23 Oct 2025 20:40:55 +0200 Subject: [PATCH 1/4] Fix shallow assy exporting --- cadquery/occ_impl/assembly.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cadquery/occ_impl/assembly.py b/cadquery/occ_impl/assembly.py index d76422bb7..e08c4a6c1 100644 --- a/cadquery/occ_impl/assembly.py +++ b/cadquery/occ_impl/assembly.py @@ -413,18 +413,27 @@ def _toCAF(el: AssemblyProtocol, ancestor: TDF_Label | None) -> TDF_Label: for child in el.children: _toCAF(child, subassy) + # final rv construction if ancestor and el.children: tool.AddComponent(ancestor, subassy, el.loc.wrapped) rv = subassy elif ancestor: rv = ancestor - else: + elif el.children: # update the top level location rv = TDF_Label() # NB: additional label is needed to apply the location - # set location, is location is identity return subassy + # set location, if location is identity return subassy tool.SetLocation(subassy, assy.loc.wrapped, rv) setName(rv, assy.name, tool) + elif el.obj: + # only root with an object + rv = tool.NewShape() + + lab = tool.AddComponent(rv, lab, el.loc.wrapped) + setName(lab, f"{el.name}", tool) + else: + raise ValueError("Cannot convert an empty assembly to CAF") return rv From 92c2862e540ab66a4f65e68c836ec9a9eeb6752b Mon Sep 17 00:00:00 2001 From: AU Date: Thu, 23 Oct 2025 22:00:02 +0200 Subject: [PATCH 2/4] toCAF edge cases test Add test for shallow assembly edge case in toCAF. --- tests/test_assembly.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_assembly.py b/tests/test_assembly.py index 4e73b518d..db1884bf2 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -2328,3 +2328,15 @@ def test_special_methods(subshape_assy): with pytest.raises(AttributeError): subshape_assy.cube_123456 + + +def test_shallow_assy(): + """ + toCAF edge case. + """ + + # shallow assy + toCAF(ca.Assembly(cq.Workplane().box(1, 1, 1))) + + with pytest.raises(ValueError): + toCAF(ca.Assembly(cq.Workplane().box(1, 1, 1))) From 41de172a6823dbee2c7678aa62880666524b4b9b Mon Sep 17 00:00:00 2001 From: AU Date: Thu, 23 Oct 2025 22:18:53 +0200 Subject: [PATCH 3/4] typo fix --- tests/test_assembly.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_assembly.py b/tests/test_assembly.py index db1884bf2..43fc540cb 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -2336,7 +2336,7 @@ def test_shallow_assy(): """ # shallow assy - toCAF(ca.Assembly(cq.Workplane().box(1, 1, 1))) + toCAF(cq.Assembly(cq.Workplane().box(1, 1, 1))) with pytest.raises(ValueError): - toCAF(ca.Assembly(cq.Workplane().box(1, 1, 1))) + toCAF(cq.Assembly(cq.Workplane().box(1, 1, 1))) From 48d28c6898a2c6d90b608e255cad312e0e9253ed Mon Sep 17 00:00:00 2001 From: AU Date: Fri, 24 Oct 2025 00:07:43 +0200 Subject: [PATCH 4/4] Fix test --- tests/test_assembly.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_assembly.py b/tests/test_assembly.py index 43fc540cb..5d0597c18 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -2339,4 +2339,4 @@ def test_shallow_assy(): toCAF(cq.Assembly(cq.Workplane().box(1, 1, 1))) with pytest.raises(ValueError): - toCAF(cq.Assembly(cq.Workplane().box(1, 1, 1))) + toCAF(cq.Assembly())