Python Script Repeating Issue

I’m having trouble with a Python Script module repeating a ‘for’ loop several times resulting in overlapping redundant nodes.
The loop repeats because of a list that the for loop has no interaction with (the list I use for a earlier part of the code only).

I’ve stripped the code back to only the relevant for loop and am unsure why this reacts with input that hasn’t been referenced.

Can someone please explain why this happens and if there is a way to avoid this? I prefer to script fewer modules to keep my work tidy.

My Grasshopper Script:

Partial of Code Showing Not Related to storyHeightArray:
image

Rhino Output, Bottom Nodes Repeat:

Hi @dgp.proudfoot

If you want to get help with code, which in this case is pure debugging, please do not post just a screenshot. This would mean that someone else, who did not even write your code, will have to re-write it and re-invent it.

Please be kind, and go ahead, also submit the definition.

Without knowing more, I could speculate a bug with indices.

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi @piac,

My apologies, I’m new to this forum!
Here is my script.

Any assistance would be greatly appreciated!MomentResistingFrame-27112017.gh (11.2 KB)

Try setting storyHeightArray as list access - that should fix it.

Grasshopper iterates automatically. If you feed the circle component 1 point, you get 1 circle. If you give it a list of points, you get a list of circles.

Script components are the same. If you give a python component a list as input, by default it will run for each item in the list. If you want to treat each list as a discrete input, you can right click and set to list access.

Does that make sense? It takes a little experience to go smoothly from python data back and forth from Grasshopper.

As @owen mentions you will have to set your floor elevations as a list and then iterate through them within the code.
Something like this will give you the sequence you’re looking for.

for i in range(len(storyHeightArray)-1):
    locZ =storyHeightArray[i]
for j in range(nSpans+1):
    locX = j*baySpan
    node = rs.AddPoint(locX, 0, locZ)
    nodeArray.append(node)

I would strongly encourage you to store your points as a two-dimensional array since you want to connect them as beams and columns on a later step.

Hope this helps.

Best,
M

Awesome. Thanks for the advice!
I’ve managed to get that working exactly as needed!

Appreciate the help :slight_smile: