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.
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 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.
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)
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.
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.
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.
Hello! Thanks a lot for making and publishing this amazing script! I am trying to use it for an optimization of the segmentation of decommissioned objects in order to create a truss out of repurposed materials. I am using as inputs the lengths of the pieces I have and the lengths of the truss components that I need, but the excluded output of the python script is null and I don’t know why. I definitely have more pieces left after the fitting and I played around with the script but to no positive results. Could you please help me?
Hi @Thanassis_Svarnas, remember to @ if you wish a person to see your post.
Could you send a minimal version of your script, with maybe the lengths internalised?
What I’m seeing from your pic is a that you are giving a lot of and quite specific precut lengths to the script. What you’re seemingly doing is not the intended purpose of the script, but nevertheless should work. If you send the material, I can have a look.
Hello @Toni_Osterlund, thank you very much for your quick response. I will remember your note for next time.
The script doesn’t have the same purpose indeed, but I thought that they had some similar aspects. The purpose of my script is for the user to add a surface that they want to make it stand using a truss structure. The components that make up the truss will be made of structures that have reached their end-of-life and are being decommissioned. The idea is that, from a circular point of view, it is better to use these materials than using virgin materials.
The truss itself isn’t the central issue of the script, so I have made an overly simplified parametric script about its creation, which I have not included in the file I am attaching. I have internalised the truss and the pieces that I have from the repurposing process, which are used as “available beams”. As you will notice, these pieces don’t have the same width, which should definitely be a part of the script when it comes to the fitting of the required lengths to the available ones, but I haven’t yet solved this part either (I am currently working on making this part work). I am new to grasshopper, so it takes me a lot of time to figure things out, and I am sorry for any misunderstandings.
Hi @Thanassis_Svarnas
I am not understanding the issue here..?
You see to pass in 67parts to be fitted onto 42 different precuts. And they all seem to fit, taking only 16pcs out of the 42 precuts.
Ok, I think that I have not even considered the use of decimal values in the making of this, as 1mm accuracy is quite accurate already when packing material. Even the cutting loss on a circular saw is around 3mm. So, there is propably an unwanted float->int conversion happening somewhere.
Found it. Right click lengths input and from Type hint, set the value to float.
However - disclaimer - if you wish to use this in real world setting, you must add some extra length per part in order to take cutting tool width in to account.
EDIT:
Just realised this part in your comment. Yeah… This script works on 1d packing, so just sorting lengths on a given length. If you wish to incorporate length AND width, then you must use 2D packing.
Look for OpenNest plugin, you’ll find the solution there.