Optimizing cutting length for model making

Hi all,

I am currently building a model and have limited materials to use, 1 meter thin steel rods. I have a list of lengths to cut too, and trying to optimize the data so i find the right combination of length that would fit this 1 meter. So i would need to add a combination of numbers that approximates 1 meter (cant be more) for all the values on the list. This may be combining 5 numbers or 2 numbers untill all of the numbers are used. Is it possible to do this with grasshopper without using python?

For example, one combination could be item 23 and 24: (426+456 =884) and item 16, 17, 18 (315+ 324+334 = 943), etc. What would be the most efficient way to do this? I hope with makes sense.

optimazing cutting Length.gh (8.9 KB)


Hi @seraphin_bouchard
Here’s a script I’ve constructed for just that purpose. It utilises ordered best-fit bin packing - basically 1D nesting. Included is a small visualisation of the nesting.

The code is a mess, but it works - I’ve developed this and used it throughout several projects. First in calculating the amounts needed, and then nesting the finished pieces.

I know you anly wanted 1000mm precuts, but I added the 1200 as well so you see how to add different precut lengths and amounts there.

optimazing cutting Length.gh (23.5 KB)


Great! this works perfectly. Thanks a lot :slight_smile:

This tool is awesome for my workflow. Thanks !

I know this is an old thread but does anyone have a clue when the pieces I need to be cut don’t fit inside the precut lengths the script doesn’t behave properly and non-existent precut length material gets added to the list and the pieces gets shuffled on those? Any way to modify the script so it has the functions it currently does and if there are any pieces that don’t fit in the precut lengths output that as a separate list along with a list of material used & pieces to be cut from those without adding materials to precut length list? What I want to use it for is similar to OP’s request where I have a bunch of linear materials on hand and I’m trying to see which pieces I can cut with them and what pieces don’t fit so I can streamline my design process. Any help is appreciated!

Hi @User_aaa
could you send a file with the proper data embedded?

Of the top of my head - if you know already that you have parts that are too long for the precuts, you should filter them out before nesting. Quite a simple comparison between part length and precut length.

1 Like

Hi @Toni_Osterlund thank you for your quick response.
Even taking the file you uploaded as an example, and change the precut amounts to fewer numbers so that not all the pieces can fit (image below)

the number of precut pieces used at the end of the script is actually more than the pieces available

and I was wondering if there is a way so that it only tries to fit whatever piece it can fit into the available precut piece and output a separate list of pieces that don’t fit. Currently, it looks like it adds non-existent pieces and reshuffles the pieces onto those to fit?
optimazing cutting Length (2).gh (31.0 KB)

@User_aaa Yeah, there seemed to be a bug - or I’ve actually never thought much about it, as long as I was getting the amount of precuts I needed. Once the precut list was exhausted, the script just kept running regardless.

But now, I fixed it. So it should work properly.
The used precuts are shown nested, and the Excluded output puts out the ones that did not fit.

Once the precut list is empty, I just dump all remainder to the Excluded.

And as this is ordered bin-packing, the excluded parts are from the shorter end of the sorted list of lengths.

Optimizing cutting length.gh (31.3 KB)

This is perfect thank you so much for your help!

1 Like

Hi Toni,

a great addition to this component would be to add an extra input for part names.
In fact, one could have parts which are different, but have the same lengths.
In my case, those are beveled wood beams.

With part names output in parallel to the length output, it becomes possible to label the parts on the nesting by their name instead of simply indicating the lengths which implies a tedious matching process.

I tried to fix that problem with a silly “trick” : I add a random number to the decimals, then multiply the values by a big number (since the tool only considers integers), and divide by the same number in the end.
When I’m lucky (depending on the random seed), I indeed get different values for lengths and then can match these with the initial part names… Phew !
230929_PROH_Nesting 1D with part names.gh (43.1 KB)

Hi @osuire
this is important feature of course, and is readily available as is.

Just use the “I” output from the component to get the index no. of each nested component.
EDIT: I saw you added a file. But I think the logic here will work on your case.

Here, I created some dummy names, and you can see how to get the results back as a list of part names.

Optimizing cutting length(1).gh (29.5 KB)

I have actually used this script quite a lot in my work in timber and aluminium fabrication. I have created per part fabrication files, and then use this script to compile the files into precut-sized programs. It has been a really good aid for me.


Awesome, how could I not see this ?
Many thanks.

1 Like