Skip to content

Commit 4bf733f

Browse files
committed
Assembly export: do not add leaf component when shapes is empty (CadQuery#993)
1 parent 9c525bc commit 4bf733f

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

cadquery/occ_impl/assembly.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,31 @@ def toCAF(
138138
# add leafs and subassemblies
139139
subassys: Dict[str, Tuple[TDF_Label, Location]] = {}
140140
for k, v in assy.traverse():
141-
# leaf part
142-
lab = tool.NewShape()
143-
tool.SetShape(lab, Compound.makeCompound(v.shapes).wrapped)
144-
setName(lab, f"{k}_part", tool)
145-
146141
# assy part
147142
subassy = tool.NewShape()
148-
tool.AddComponent(subassy, lab, TopLoc_Location())
149143
setName(subassy, k, tool)
150144

151-
# handle colors - this logic is needed for proper STEP export
152-
color = v.color
153-
tmp = v
154-
if coloredSTEP:
155-
while not color and tmp.parent:
156-
tmp = tmp.parent
157-
color = tmp.color
158-
if color:
159-
setColor(lab, color, ctool)
160-
else:
161-
if color:
162-
setColor(subassy, color, ctool)
145+
if len(v.shapes) > 0:
146+
# leaf part
147+
lab = tool.NewShape()
148+
tool.SetShape(lab, Compound.makeCompound(v.shapes).wrapped)
149+
setName(lab, f"{k}_part", tool)
150+
151+
tool.AddComponent(subassy, lab, TopLoc_Location())
152+
setName(subassy, k, tool)
153+
154+
# handle colors - this logic is needed for proper STEP export
155+
color = v.color
156+
tmp = v
157+
if coloredSTEP:
158+
while not color and tmp.parent:
159+
tmp = tmp.parent
160+
color = tmp.color
161+
if color:
162+
setColor(lab, color, ctool)
163+
else:
164+
if color:
165+
setColor(subassy, color, ctool)
163166

164167
subassys[k] = (subassy, v.loc)
165168

0 commit comments

Comments
 (0)