Tests to make sure that copied children in assemblies work correctly.
(tmpdir)
| 1228 | |
| 1229 | |
| 1230 | def test_copied_assembly_import(tmpdir): |
| 1231 | """ |
| 1232 | Tests to make sure that copied children in assemblies work correctly. |
| 1233 | """ |
| 1234 | from cadquery import Assembly, Location, Color |
| 1235 | from cadquery.func import box, rect |
| 1236 | |
| 1237 | # prepare the model |
| 1238 | def make_model(name: str, COPY: bool): |
| 1239 | |
| 1240 | b = box(1, 1, 1) |
| 1241 | |
| 1242 | assy = Assembly(name="test_assy") |
| 1243 | assy.add(box(1, 2, 5), color=Color("green")) |
| 1244 | |
| 1245 | for i, v in enumerate(rect(10, 10).vertices()): |
| 1246 | assy.add( |
| 1247 | b.copy() if COPY else b, |
| 1248 | name=f"element_{i}", |
| 1249 | loc=Location(v.Center()), |
| 1250 | color=Color("red"), |
| 1251 | ) |
| 1252 | |
| 1253 | with chdir(tmpdir): |
| 1254 | assy.export(name) |
| 1255 | |
| 1256 | return assy |
| 1257 | |
| 1258 | make_model("test_assy_copy.step", True) |
| 1259 | make_model("test_assy.step", False) |
| 1260 | |
| 1261 | # import the assy with copies |
| 1262 | with chdir(tmpdir): |
| 1263 | assy_copy = Assembly.importStep("test_assy_copy.step") |
| 1264 | assert 5 == len(assy_copy.children) |
| 1265 | |
| 1266 | # import the assy without copies |
| 1267 | with chdir(tmpdir): |
| 1268 | assy_normal = Assembly.importStep("test_assy.step") |
| 1269 | assert 5 == len(assy_normal.children) |
| 1270 | |
| 1271 | |
| 1272 | def test_nested_subassembly_step_import(tmpdir): |
nothing calls this directly
no test coverage detected