Skip to content

Commit 3cd327a

Browse files
fix: Transform order in subassembly (#1629)
* fix: Transform order in subassembly * test: Test assembly transform order * Use approx comparison * Fixed test * Black fix * Import approx * typo fix --------- Co-authored-by: AU <[email protected]>
1 parent 8ea37a7 commit 3cd327a

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

cadquery/assembly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ def _subloc(self, name: str) -> Tuple[Location, str]:
290290
obj = cast(Assembly, obj.parent)
291291
name_out = obj.name
292292

293-
rv = reduce(lambda l1, l2: l1 * l2, locs)
293+
# This must reduce in the order of (parent, ..., child)
294+
rv = reduce(lambda l1, l2: l2 * l1, locs)
294295

295296
return (rv, name_out)
296297

tests/test_assembly.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import copy
66
from pathlib import Path, PurePath
77
import re
8+
from pytest import approx
89

910
import cadquery as cq
1011
from cadquery.occ_impl.exporters.assembly import (
@@ -1608,3 +1609,36 @@ def test_imprinting(touching_assy, disjoint_assy):
16081609

16091610
for s in r.Solids():
16101611
assert s in o
1612+
1613+
1614+
def test_order_of_transform():
1615+
1616+
part = cq.Workplane().box(1, 1, 1).faces(">Z").vertices("<XY").tag("vtag")
1617+
marker = cq.Workplane().sphere(0.2)
1618+
1619+
assy0 = cq.Assembly().add(
1620+
part, name="part1", loc=cq.Location((0, 0, 1.5), (0, 0, 1), 45),
1621+
)
1622+
1623+
assy1 = (
1624+
cq.Assembly()
1625+
.add(assy0, name="assy0", loc=cq.Location(2, 0, 0))
1626+
.add(marker, name="marker1")
1627+
)
1628+
1629+
# attach the first marker to the tagged corner
1630+
assy1.constrain("assy0/part1", "Fixed")
1631+
assy1.constrain("marker1", "assy0/part1?vtag", "Point")
1632+
assy1.solve()
1633+
1634+
assy2 = cq.Assembly().add(assy1, name="assy1").add(marker, name="marker2")
1635+
1636+
# attach the second marker to the tagged corner, but this time with nesting
1637+
assy2.constrain("assy1/marker1", "Fixed")
1638+
assy2.constrain("marker2", "assy1/assy0/part1?vtag", "Point")
1639+
assy2.solve()
1640+
1641+
# marker1 and marker2 should coincide
1642+
m1, m2 = assy2.toCompound().Solids()
1643+
1644+
assert (m1.Center() - m2.Center()).Length == approx(0)

0 commit comments

Comments
 (0)