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

Script for Bin Packing (automatically fitting items onto artboards)

Community Expert ,
Oct 18, 2024 Oct 18, 2024

Copy link to clipboard

Copied

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

Views

668

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Oct 22, 2024 Oct 22, 2024

I have a problem with the display of the degree sign in the UI. I changed it to Unicode "Allow 90\u00b0 rotation".

New test:

SergeyOsokin_0-1729656063704.png

SergeyOsokin_0-1729656217490.png

 

Votes

Translate

Translate
Adobe
Enthusiast ,
Oct 19, 2024 Oct 19, 2024

Copy link to clipboard

Copied

Thanks Mark for sharing this. I think I have come across these JS libraries. The result is acceptable, although even on rectangles sometimes the result can be corrected manually if the user can see that the empty areas can be filled in.

 

Votes

Translate

Translate

Report

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 20, 2024 Oct 20, 2024

Copy link to clipboard

Copied

Hi @Sergey Osokin thanks for checking it out. Yes it is a basic algorithm that only works with rectangles—I did look at the more sophisticated algorithms but they were a major time investment to understand!

 

When I look at your "test 1.jpg" it gives me an idea to add an improvement—watch this space!

 

And your "test.jpg" shows a strange bug which I haven't noticed. I will look into that. Thanks again!

- Mark

Votes

Translate

Translate

Report

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
Enthusiast ,
Oct 20, 2024 Oct 20, 2024

Copy link to clipboard

Copied

It seems to me that ExtendScript would be too slow if the goal is to maximize compact packaging. I know that printing companies buy specialized software for this, which is not cheap.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi @Sergey Osokin, yes, and libaries like svgnest that are amazing, but too complex for me to port to ExtendScript.

 

But for now, I've improved my script's capabilities by (optionally) first rotating each item so that it fits within the smallest rectangle possible. This can make a big difference when packing arbitrary shapes.

 

I've updated the code on github.

- Mark

 

P.S. Here's an example of the new functionality:

showing-rotation.png

Votes

Translate

Translate

Report

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
Enthusiast ,
Oct 22, 2024 Oct 22, 2024

Copy link to clipboard

Copied

I have a problem with the display of the degree sign in the UI. I changed it to Unicode "Allow 90\u00b0 rotation".

New test:

SergeyOsokin_0-1729656063704.png

SergeyOsokin_0-1729656217490.png

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks again @Sergey Osokin, I have made your change to the repo. As you can see the algorithm is "dumb" in the sense that it has no idea which item is best to pack next. That is why the scripts simply do a bunch of different sorts and then random shuffles. If you think of a good sorting scheme let me know!

- Mark

Votes

Translate

Translate

Report

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 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

This is nice! Thanks for sharing @m1b!

Votes

Translate

Translate

Report

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