pylabrobot.resources.Carrier.assign_child_by_anchor#
- Carrier.assign_child_by_anchor(resource: Resource, parent_anchor: tuple[str, str, str] | str = ('l', 'f', 'b'), child_anchor: tuple[str, str, str] | str = ('l', 'f', 'b'), reassign: bool = True)#
Assign a child resource by aligning anchor points.
This method computes the location needed to align the specified anchor points of the parent and child resources, then calls
assign_child_resource()with the computed location.- Parameters:
resource (Resource) – The resource to assign.
parent_anchor (tuple[str, str, str] | str) – Anchor specifiers for the parent. Can be either: - A tuple of (x, y, z) strings, or - A 3-character string (e.g., “lfb” for left-front-bottom) Each element can be: x:
"l"/"left","c"/"center", or"r"/"right"y:"b"/"back","c"/"center", or"f"/"front"z:"t"/"top","c"/"center", or"b"/"bottom"Defaults to left-front-bottom.child_anchor (tuple[str, str, str] | str) – Anchor specifiers for the child (same format as parent_anchor). Defaults to left-front-bottom.
reassign (bool) – If
False, an error will be raised if the resource to be assigned is already assigned to this resource. Defaults toTrue.
Examples
Align left-front-bottom (default behavior):
>>> parent = Resource("parent", size_x=100, size_y=100, size_z=10) >>> child = Resource("child", size_x=80, size_y=80, size_z=5) >>> parent.assign_child_by_anchor(child) # Both default to LFB
Align the center-center-bottom using tuple syntax:
>>> parent.assign_child_by_anchor(child, parent_anchor=("c", "c", "b"), ... child_anchor=("c", "c", "b"))
Align the center-center-bottom using string syntax:
>>> parent.assign_child_by_anchor(child, parent_anchor="ccb", child_anchor="ccb")
Stack on top by aligning parent’s top with child’s bottom:
>>> parent.assign_child_by_anchor(child, parent_anchor="lft", child_anchor="lfb")