This example demonstrates the full workflow: initializing the packer, adding a bin, adding multiple items, executing the packing algorithm, and visualizing the result.
from py3dbp import Packer, Bin, Item, Painter
import time
start = time.time()
# init packing function
packer = Packer()
# init bin
box = Bin('example',(30, 10, 15), 99, 0)
packer.addBin(box)
# add item
packer.addItem(Item('test1', 'test','cube',(9, 8, 7), 1, 1, 100, True,'red'))
packer.addItem(Item('test2', 'test','cube',(4, 25, 1), 1, 1, 100, True,'blue'))
packer.addItem(Item('test3', 'test','cube',(2, 13, 5), 1, 1, 100, True,'gray'))
packer.addItem(Item('test4', 'test','cube',(7, 5, 4), 1, 1, 100, True,'orange'))
packer.addItem(Item('test5', 'test','cube',(10, 5, 2), 1, 1, 100, True,'lawngreen'))
# calculate packing
packer.pack(
bigger_first=True,
fix_point=True,
distribute_items=True,
check_stable=True,
support_surface_ratio=0.75,
number_of_decimals=0
)
# paint the results
for b in packer:
painter = Painter(b)
fig = painter.plotBoxAndItems(
title=b.partno,
alpha=0.2,
write_num=True,
fontsize=10
)
fig.show()