Trying to use my "editpythonscript" inside grasshopper

Hi! I was trying to use one script I made in the “editpythonscript” inside grasshopper with no luck. Not sure why it is not working, the scripts looks like this:

But when trying to use the exact same script in grasshopper it is not working? Any ideas why this is happening?

Best Regards,


Since you’re writing about Grasshopper and Python, I’m guessing that you’re using the GHPython component?
If that’s the case, then you’ve forgotten to pass anything out of it. It has a default output a for this, which you can rename to whatever.
It works by passing something to a variable of the same name.

However, in your case your makeBox() function first needs to return something. Currently, it’s only calling rs.AddBox(), which adds a box to the Rhino document.
In Grasshopper, you’re better off using only RhinoCommon - the API -, and getting rid of the rhinoscriptsyntax code. It’s primarily meant to script in Rhino.

import Rhino.Geometry as rg
import math

HALF_PI = 0.5 * math.pi

def make_box(w, h, d, angle):
    corners = []
    delta = math.atan((w * 0.5) / (d * 0.5)) + math.radians(angle)
    length = math.sqrt((d * 0.5)**2 + (w * 0.5)**2)
    for j in xrange(2):
        for i in xrange(4):
            x = -math.cos(delta + i * HALF_PI) * length
            y = -math.sin(delta + i * HALF_PI) * length
            corners.append(rg.Point3d(x, y, h * j))
    return rg.Box(rg.Plane.WorldXY, corners)

if __name__ == "__main__":
    a = make_box(10, 20, 10, 5.0)

I don’t know what all the angle stuff is about, but this should work.

thank you! this works :slight_smile: