Browsed the first page of most recent posts but this doesn’t seem to be a big issue…
I’m now at a point where I master some Dynamo functions in designscript, so code rather than the input/output blocks, and try to use functions wherever I have to repeat a few lines of code. But since a little while, I keep getting an indexation error whenever I use a while() loop and try to put the result into a list. I’ve tried the most common steps to find the error, but it drives me nuts to have to close and re-open the file every time.
So this is basically how I learned it: I first declare i = 0, then start a loop to test the value of i against another parameter. It increases at the end of each loop (i = i + 1) (by the way… whatever happened to i++?) but before that I put the result into a collection (list[i] = result).
The error occurs at the last step, when I’m using i as an index for the returned list. My best translation from Dutch: ‘The index is outside the range. It cannot be negative and must be smaller than the size of the collection.’
Here’s a quick sample in which I try to generate ten panels of 600 by 1000 units:
<span style=“color: #8c5eaa;”>def</span> PlacePanels(midpoint)
{
surfaces = {};
startpoint = midpoint;
vector = <span style=“color: #2e998f;”>Vector</span>.<span style=“color: #417693;”>ByCoordinates</span>(<span style=“color: #2585e5;”>1</span>, <span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>0</span>);
vecPerp = vector.<span style=“color: #417693;”>Rotate</span>(<span style=“color: #2e998f;”>Vector</span>.<span style=“color: #417693;”>ByCoordinates</span>(<span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>1</span>), <span style=“color: #2585e5;”>90</span>);
path;
profile;
surface;
i = <span style=“color: #2585e5;”>0</span>;
<span style=“color: #8c5eaa;”>return</span> = [<span style=“color: #8c5eaa;”>Imperative</span>]
{
<span style=“color: #8c5eaa;”>while</span> (i < <span style=“color: #2585e5;”>10</span>)
{
path = <span style=“color: #2e998f;”>Line</span>.<span style=“color: #417693;”>ByStartPointDirectionLength</span>(startpoint, vector, <span style=“color: #2585e5;”>600</span>);
profile = <span style=“color: #2e998f;”>Line</span>.<span style=“color: #417693;”>ByStartPointDirectionLength</span>(startpoint, vecPerp, <span style=“color: #2585e5;”>1000</span>);
surface = <span style=“color: #2e998f;”>Surface</span>.<span style=“color: #417693;”>BySweep</span>(path, profile);
surfaces[i] = surface;
i = i + <span style=“color: #2585e5;”>1</span>;
startpoint = path.<span style=“color: #417693;”>EndPoint</span>;
}
<span style=“color: #8c5eaa;”>return</span> = i;
}
};
The same happens in a for() loop:
<span style=“color: #8c5eaa;”>def</span> PlacePanels(midpoint)
{
surfaces = <span style=“color: #2585e5;”>0</span>…<span style=“color: #2585e5;”>9</span>;
startpoint = midpoint;
vector = <span style=“color: #2e998f;”>Vector</span>.<span style=“color: #417693;”>ByCoordinates</span>(<span style=“color: #2585e5;”>1</span>, <span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>0</span>);
vecPerp = vector.<span style=“color: #417693;”>Rotate</span>(<span style=“color: #2e998f;”>Vector</span>.<span style=“color: #417693;”>ByCoordinates</span>(<span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>0</span>, <span style=“color: #2585e5;”>1</span>), <span style=“color: #2585e5;”>90</span>);
path;
profile;
surface;
<span style=“color: #8c5eaa;”>return</span> = [<span style=“color: #8c5eaa;”>Imperative</span>]
{
<span style=“color: #8c5eaa;”>for</span>(surface <span style=“color: #8c5eaa;”>in</span> surfaces)
{
path = <span style=“color: #2e998f;”>Line</span>.<span style=“color: #417693;”>ByStartPointDirectionLength</span>(startpoint, vector, <span style=“color: #2585e5;”>600</span>);
profile = <span style=“color: #2e998f;”>Line</span>.<span style=“color: #417693;”>ByStartPointDirectionLength</span>(startpoint, vecPerp, <span style=“color: #2585e5;”>1000</span>);
surface = <span style=“color: #2e998f;”>Surface</span>.<span style=“color: #417693;”>BySweep</span>(path, profile);
startpoint = path.<span style=“color: #417693;”>EndPoint</span>;
}
<span style=“color: #8c5eaa;”>return</span> = surfaces;
}
};
Does anyone have a clue what’s causing this, or how to fix it? I’m starting to run out of options here.
Kind regards, Bram