Loop/Imperative not working

python
dynamo
#1

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?

#2

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
#3

Hi Viktor,

Thanks for the quick reply. It’s an answer for the 1/3 :wink:

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

#4

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
#5

Nice suggestion! I have to find out some new commando’s again :wink: 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.

#6

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

#7

Take a look at this:

#8

Thanks for the link, I understand the command but I don’t get the error with this command on list and float. The script works perfect when I enter just a number in a code block en put this in IN[0].

#9

1 Like
#10

Super Victor! I gues I get the point. In the formula we couldn’t use a list on “c=sheet”.
I thought it was tackled at the input on line 7.
In dynamo I used to deconstruct node before IN[0], nice to see how to fix it python.

Thanks again!