(simple_assy, nested_assy)
| 2148 | |
| 2149 | |
| 2150 | def test_toCompound(simple_assy, nested_assy): |
| 2151 | |
| 2152 | c0 = simple_assy.toCompound() |
| 2153 | assert isinstance(c0, cq.Compound) |
| 2154 | assert len(c0.Solids()) == 4 |
| 2155 | |
| 2156 | c1 = nested_assy.toCompound() |
| 2157 | assert isinstance(c1, cq.Compound) |
| 2158 | assert len(c1.Solids()) == 4 |
| 2159 | |
| 2160 | # check nested assy location appears in compound |
| 2161 | # create four boxes, stack them on top of each other, check highest face is in final compound |
| 2162 | box0 = cq.Workplane().box(1, 1, 3, centered=(True, True, False)) |
| 2163 | box1 = cq.Workplane().box(1, 1, 4) |
| 2164 | box2 = cq.Workplane().box(1, 1, 5) |
| 2165 | box3 = cq.Workplane().box(1, 1, 6) |
| 2166 | # top level assy |
| 2167 | assy0 = cq.Assembly(box0, name="box0") |
| 2168 | assy0.add(box1, name="box1") |
| 2169 | assy0.constrain("box0@faces@>Z", "box1@faces@<Z", "Plane") |
| 2170 | # subassy |
| 2171 | assy1 = cq.Assembly() |
| 2172 | assy1.add(box2, name="box2") |
| 2173 | assy1.add(box3, name="box3") |
| 2174 | assy1.constrain("box2@faces@>Z", "box3@faces@<Z", "Plane") |
| 2175 | assy1.solve() |
| 2176 | assy0.add(assy1, name="assy1") |
| 2177 | assy0.constrain("box1@faces@>Z", "assy1/box2@faces@<Z", "Plane") |
| 2178 | # before solving there should be no face with Center = (0, 0, 18) |
| 2179 | c2 = assy0.toCompound() |
| 2180 | assert not cq.Vector(0, 0, 18) in [x.Center() for x in c2.Faces()] |
| 2181 | # after solving there should be a face with Center = (0, 0, 18) |
| 2182 | assy0.solve() |
| 2183 | c3 = assy0.toCompound() |
| 2184 | assert cq.Vector(0, 0, 18) in [x.Center() for x in c3.Faces()] |
| 2185 | # also check with bounding box |
| 2186 | assert c3.BoundingBox().zlen == pytest.approx(18) |
| 2187 | |
| 2188 | |
| 2189 | @pytest.mark.parametrize("origin", [(0, 0, 0), (10, -10, 10)]) |
nothing calls this directly
no test coverage detected