Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cadquery/occ_impl/assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(cq.Assembly(cq.Workplane().box(1, 1, 1)))

with pytest.raises(ValueError):
toCAF(cq.Assembly())