Hi, I am kind of a noob of Python, but I am using Python to build a node in Dynamo for Civil 3D, and I’m facing some problems with the following loop, giving me the error “Traceback (most recent call last): File “”, line 16, in IndexError: index out of range: 0”
Strategy = IN[0]
TotStrategies = IN[1]
Packs_C_D = IN[2]
Packs_B = IN[3]
Packs_A = IN[4]
Packs_Indexes=[]
i=0
for i in range(0,TotStrategies,1):
if Strategy[i] == 'a':
Packs_Indexes[i]=Packs_A
elif Strategy[i] == 'b':
Packs_Indexes[i]=Packs_B
else :
Packs_Indexes[i]=Packs_C_D
OUT = Packs_Indexes
The script should build a new list (Packs_Indexes) putting the elements (lists themselves: Packs_A, Packs_B, Packs_C_D) at the index i consequently to a condition.
I also tried with
for i in range(0,TotStrategies,1):
if Strategy[i] == 'a':
Packs_Indexes.append(Packs_A)
elif Strategy[i] == 'b':
Packs_Indexes.append(Packs_B)
else :
Packs_Indexes.append(Packs_C_D)
OUT = Packs_Indexes
In this case, I don’t have the same problem, but the calculation goes on for hours and then eventually the software crash.
done and sadly it doesn’t help… I also tried with a “while” loop, or specifying the step in the for loop. I have the idea that maybe the problem is in the deepness of the lists (vectors and matrix, basically), but it shold work nicely as it did in other script I used before
Oh, I’m sorry, I misunderstood, I thought you meant len(Strategy), that is the vector of strategies, while TotStrategies is an int. I’ll post the pics of the graph as you asked
OK, starting problem solved… that’s basically why when I use “append” it doesn’t give me any error, but on the other hand the software crashes after few minutes it’s running. I hope it is not an hardware problem (and anyway I also tried to use a virtual memory to bust the ram).
Thank you, but still I dont get it: how can it be an infinite loop if the range has a beginning (0), an end (TotStrategies (=54)) and a step (1)? I mean, the condition to start the loop should stop to be true when i=55!
Again, thank you so much for your kind reply;
I wasn’t clear before: the Dynamo file doesn’t write on any excel file (I didn’t arrive at that point yet, and I’ll write on a different excel file).
Eventually, it was a hardware problem. The script was correct, but the amount of calculations was too much for my 8 gb RAM, it needed a 64gbRam workstation to run successfully…