Remove item from list while iteration for while

How To Remove Item From list While Iteration and get the index of

@ahmedabdlsalamm can you show what you are after?

i want to reuse the waste as a stock again so
i want to use it and when it fits with minimum waste to remove the length fom the list and then go to the next length

I believe that this bin packing node should already do this.

Since this node repeats the one size bin until all items are packed, you’d just need to incorporate the complete list of things you need to pack into the values input for the node.

if that isn’t the case, you’d likely want to utilize another bin packing node, or build your own via Python.

the problem is when i use the node and add the waste to the bin size
the node working with all the length list so
what i want to do
try the firist bin size with the length list when get the less waste from the firist bin size
it take the index of length that achive the least waste and remove the used length from the length list then go to the second bin size and again untill it reach 12 m and finish


the python code is here what should i add to


#In this script values are sorted into bins with a fixed maximum size.
#The sorting occurs according to the First Fit Decreasing algorithm.
#The input for "Values" need to be sorted in Decreasing order for an optimal result
#Authored by Dieter Vermeulen, Autodesk (2017)

import clr

Values=IN[0]
BinSize=IN[1]

Bin=[]  			#Array of packed bins
Waste=[]			#List of waste per bin
ValueIndices=[]	#Index of the value assigned to the bin
result=False
j=0 #Initiate counter for the sorting index

for val in Values:
	i=0  #Reset Counter for the bin assignment
	n=len(Bin)
	while (i < n):
		if Waste[i]-val >= 0:
			Bin[i].append(val)
			Waste[i]=Waste[i]-val
			ValueIndices[i].append(j)
			i=n
			result = True
		else:
			i=i+1
			result = False
			
	if not result:
			Bin.append([val])
			Waste.append(BinSize-val)
			ValueIndices.append([j])
	j=j+1	
	
#Assign your output to the OUT variable.
OUT = Bin, Waste, ValueIndices

That would be the code, but it’s still not clear to me what you’re after. Can you sketch out what you’re up to?


cut optmization 03.dyn (35.5 KB)

That what i want to do to get the list from the previous cleaned and when the waste is finished go to the other bin size (120000) the orginal length for the rebar

so what i want to do is to take the bin size from the perviuos waste ,
and an example take the length of 3000 to match with the best fit from the list and when do this remove this length that fit with (3000) from the list and then try with 7000 to find the best fit with the length
and when it finish the firist go to the second cleaned from the used Length

@jacob.small

Still not sure what you are trying to do.

If the rebar is purchased 12 units long, you can utilize that as the bin size and this node will tell you one way to efficiently cut the stock to length with the least amount of waste. That waste is just that, waste which cannot be utilized again on site (at least not in any efficient method I have seen).

If your goal is something other then this you likely need a custom packing algorithm. You could look into the Refinery toolkit, or build your own; but as I can’t see what the intended use is I am lost. If you post a sketch (I have this on site, want to do this with it, and use the remainder over here) then I might be able to guide you, but writing a custom packing algorithm isn’t something I can take on at this time.