MCPcopy
hub / github.com/CadQuery/cadquery / test_toCompound

Function test_toCompound

tests/test_assembly.py:2150–2186  ·  view source on GitHub ↗
(simple_assy, nested_assy)

Source from the content-addressed store, hash-verified

2148
2149
2150def 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)])

Callers

nothing calls this directly

Calls 9

toCompoundMethod · 0.95
addMethod · 0.95
constrainMethod · 0.95
solveMethod · 0.95
SolidsMethod · 0.80
boxMethod · 0.80
CenterMethod · 0.45
FacesMethod · 0.45
BoundingBoxMethod · 0.45

Tested by

no test coverage detected