Mesh multiplies my output in GHPython

Hey everyone,

I have a problem with my python script in grasshopper. So far I have made a script that interpolates some data which I need to now solar radiation in relation to windows orientation. This works fine. I have another script that takes window geometry and finds orientation, slope and area which is needed for my calculation. Also works perfect. My idea is to make one script that does it all so I don’t need too many components since it gets a bit confusing with the outputs. The problem is quite simple. When I take my window mesh from grasshopper and puts it in to the script that does the interpolation it makes the interpolation script run 52 times (Matching the number of windows I have in the building atm). I have changed the input type to List - mesh since it has worked before, but it doesn’t work now. As you can see on the picture this ruins both scripts and make it all run way too many times which also makes it slow. Hopefully there is a good reason for this and it is probably just the way ghpython works - since I am still quite new to it I don’t know.
Thanks in advance and have a great weekend!
File and picture of problem is linked :slight_smile:


Working_Weatherfile.gh (53.9 KB)

Your script runs 52 times, because you’re inputting 52 geometries, each in a single branch of a data tree!

Screenshot 2022-03-05 at 17.39.35

Setting the type hint of the input to List Access doesn’t do anything, because each branch is thus considered as a separate list.

If you want to run the component once and process all geometries, for instance don’t graft the input and process the data as a list in your script:

import ghpythonlib.components as ghcomp
import math

pi = math.pi

# Ouputs lists
area = []
normals = []
slope = []
orient = []

for window in windows:
    area.append(ghcomp.Area(window))
    normals.append(ghcomp.DeconstructVector(ghcomp.FaceNormals(window)[1])[0])
    slope.append(
        (ghcomp.Angle(ghcomp.UnitZ(1), ghcomp.FaceNormals(window)[1])[0]) * 180 / pi
    )
    angle = (ghcomp.Angle(ghcomp.UnitY(1), ghcomp.FaceNormals(window)[1])[0]) * 180 / pi
    if (ghcomp.DeconstructVector(ghcomp.FaceNormals(window)[1])[0]) < 0:
        angle += 180
    orient.append(angle)

You can now also unflatten all outputs.

1 Like

Thank you so much :smiley:

1 Like