Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Script for Bin Packing (automatically fitting items onto pages)

Community Expert ,
Oct 18, 2024 Oct 18, 2024

Hi everyone, I'd like to share a script.

 

Some time ago I wrote a script for bin-packing in Illustrator (posted here on the forum) and recently another user asked me if I could make a version for Indesign, which I have now done and I've published to github (the repo has scripts for both Indesign and Illustrator).

 

To read more about the scripts, including instructions, you can visit the github repo or to jump right in you can directly download the scripts.

 

What is bin packing?

Bin packing is arranging things so that they fit into "bins". In Illustrator, the bins are artboards, and in Indesign the bins are pages.

 

This is the sort of thing you can do in Illustrator (packing 35 items into 2 artboards):

simple-packing-examples.gif

 

And here's an Indesign example, packing 146 items onto 4 pages:

demo-cropped.gif

(This animation is using the option "Divide Bins at Guides", which keeps the items clear of the guides by a set margin.)

 

I hope someone will find the scripts useful. Feel free to leave feedback here or via the github repo.

- Mark

TOPICS
Scripting
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024

Amazing Mark!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024

Thanks Brian! As usual I am standing on the shoulders of giants!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2024 Oct 19, 2024

Aren't we all?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Oct 21, 2024 Oct 21, 2024

Great work Mark!

 

Many nice settings (‘Divide Bins at Guides’, ‘Maximize’ options) will make this tool essential.

 

FYI, a much more rudimentary approach without UI stuff and extra options:

https://github.com/indiscripts/IdExtenso/tree/master/tests#rectpacktestjsx

 

I only mention it for the purpose of ​​comparing the two underlying algorithms. IdExtenso's RectPack module is based on github.com/mapbox/potpack, while yours relies on Jake Gordon's Binary Tree Bin Packing Algorithm which is probably the root reference of all existing solutions. The different implementations might be interesting to analyze in terms of performance.

 

Best,

Marc

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024

Hi @Marc Autret, thank you for your encouragement! I will be interested to compare the different approaches sometime—it fascinates me how such things work. As I'm sure you can tell I don't have a computer science background (or even programming background for that matter) and I struggle sometimes to understand, but I will press forward!

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2024 Oct 22, 2024
LATEST

Update 2024-10-23: I have added an option "Allow any rotation" which will rotate each item as needed to best fit inside a rectangle. This can improve packing significantly, depending on the shapes.

ui.png

Here's an example—the bottom items are packed into the artboards at top. Without the new option, they would never have packed as well. Also note that the "J" and "q" are text items, not outlined.

- Mark

 

showing-rotation.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines