Skip to content

Commit 52ce82d

Browse files
Fix shallow assy exporting (#1924)
* Fix shallow assy exporting * Add test for shallow assembly edge case in toCAF.
1 parent 505a18d commit 52ce82d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

cadquery/occ_impl/assembly.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,27 @@ def _toCAF(el: AssemblyProtocol, ancestor: TDF_Label | None) -> TDF_Label:
413413
for child in el.children:
414414
_toCAF(child, subassy)
415415

416+
# final rv construction
416417
if ancestor and el.children:
417418
tool.AddComponent(ancestor, subassy, el.loc.wrapped)
418419
rv = subassy
419420
elif ancestor:
420421
rv = ancestor
421-
else:
422+
elif el.children:
422423
# update the top level location
423424
rv = TDF_Label() # NB: additional label is needed to apply the location
424425

425-
# set location, is location is identity return subassy
426+
# set location, if location is identity return subassy
426427
tool.SetLocation(subassy, assy.loc.wrapped, rv)
427428
setName(rv, assy.name, tool)
429+
elif el.obj:
430+
# only root with an object
431+
rv = tool.NewShape()
432+
433+
lab = tool.AddComponent(rv, lab, el.loc.wrapped)
434+
setName(lab, f"{el.name}", tool)
435+
else:
436+
raise ValueError("Cannot convert an empty assembly to CAF")
428437

429438
return rv
430439

tests/test_assembly.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,3 +2328,15 @@ def test_special_methods(subshape_assy):
23282328

23292329
with pytest.raises(AttributeError):
23302330
subshape_assy.cube_123456
2331+
2332+
2333+
def test_shallow_assy():
2334+
"""
2335+
toCAF edge case.
2336+
"""
2337+
2338+
# shallow assy
2339+
toCAF(cq.Assembly(cq.Workplane().box(1, 1, 1)))
2340+
2341+
with pytest.raises(ValueError):
2342+
toCAF(cq.Assembly())

0 commit comments

Comments
 (0)