# Loop/Imperative not working

Hi All,
I’m trying to find a loop for dyfining how many views i can place in a length on a sheet. Only all the views have different widths.

When the length on my sheet is to small for the next view, I would like to place the next view is a new row(sublist). Can somebody help me out?

It does exactly what you’re telling it to do i.e. it checks if the space left after the view is > 0. But that space might still not be enough to place a view there. That’s why you’re getting the negative value on the next round:

That could be a quick fix, but I’m not sure if that’s the best approach for what you’re after.

3 Likes

Hi Viktor,

Let me try to explain my other questions:

1)The outcomming lists are now created per item from the “width” list (see 571-145-145-145) to 0. Is it also possible to create lists that run through the “width” list, so 0 = <571-145 -205-85-86.

2)It would be great if a new list was made after which “sheet” is reset to the starting value and the items in “width” continue. So the 2nd list = values 571-115-65-115.

Sorry, I’m just starting with Python :S

Tried unsuccessfully translating this into design script but this works in Python:

``````sheet = IN[0]
widths = IN[1]
bodem = IN[2]

output = []
t = []
c = sheet
tot = len(widths)-1
for i, w in enumerate(widths):
c -= w
if c >= bodem:
t.append(c)
else:
output.append(t)
c = sheet - w
t = [c]

if i == tot:
output.append(t)

OUT = output
``````

1 Like

Nice suggestion! I have to find out some new commando’s again thanks!

Your example looks good. Now I tried it with a longer list (old list x2). In list1 the imput (sheet) is exceeded, see image.

I’ve combined your solution with the solution of Viktor like this, and it worked out!

Thanks All!!

the code:
sheet = IN[0]
widths = IN[1]
bodem = IN[2]

output =
t =
c = sheet
for i, w in enumerate(widths):
c -= w
if (c-w) >= bodem:
t.append(w)
else:
output.append(t)
t = [w]
c = sheet

``````if i == len(widths)-1:
output.append(t)
``````

OUT = output.

Ai…a little bit to soon. Somehow the operation “-=” gives an error.