pack_layout

photonforge.pack_layout(objects, gap=0, max_size=(0, 0), aspect_ratio=0, grow_factor=1.1, sorting='best', allow_rotation=False, method='blsf', include_ports=True, layer=(0, 0), name='PACK_{i}')

Arrange components or other structures in a grid layout.

Parameters:
  • objects (Sequence[Component | Reference | Circle | Path | Polygon | Rectangle]) – Sequence of objects to arrange. They can be instances of Component, Reference, or 2D structures.

  • gap (float | Sequence[float]) – Horizontal and vertical gaps added between objects.

  • max_size (Sequence[float]) – Maximal size of the packed component. If not all objects fit in a single pack, multiple are used.

  • aspect_ratio (float) – Desired width:height ratio for the pack.

  • grow_factor (float) – Controls pack size increment. Values closer to 1 can result in tighter packs at the cost of more computation.

  • sorting (Literal['best', 'area'] | None) – Sorting option for the list of objects. If None, objects are packed in the order they are listed; 'area' will pack from largest to smallest, and "best" will try to choose the best object to pack at each iteration.

  • allow_rotation (bool) – If True, objects may be rotated by 90°.

  • method (Literal['bl', 'blsf', 'bssf', 'baf', 'cp']) – Heuristic used to select a free slot during packing. See below for information about the options.

  • include_ports (bool) – Whether or not to include ports when computing component bounds.

  • layer (tuple[int]) – If arranging geometrical structures, add them to this layer.

  • name (str) – Name template for the resulting components. Variable i is used to indicate the pack index in the case of multiple packs.

Returns:

List of components with the packed objects.

Return type:

list[Component]

Note

The available methods for selecting a free slot for packing are:

Bottom left rule ("bl"):

Use the left-most position among the lowest upper y-value options.

Best long side fit ("blsf"):

Use the position that minimizes the leftover length on the long side.

Best short side fit ("bssf"):

Use the position that minimizes the leftover length on the short side.

Best area fit ("baf"):

Use the smallest available area that fits.

Contact point rule ("cp"):

Use the position that maximizes the length of the perimeter that touches other objects.

Reference: Jukka Jylänki, A Thousand Ways to Pack the Bin – A Practical Approach to Two-Dimensional Rectangle Bin Packing, 2010.