Converting Python Script to GH Python Component

Hi All,

I could use a hand converting a python script into a GH python component. (noob alert)
Attached are both files. I’m getting null outputs from the GH component, and I cannot figure out why, but I suspect it has something to do with the point list not being read. Thanks in advance for any insight.

Hex (8.2 KB)
Hexagon_ angle (1.3 KB)

I’ll try to be more specific. The original .py script (author referenced in file) radially draws a hexagonal tiling on a 2D plane. One of the important parameters is the angle of rotation, which in my case allows the hex tiling to work without overlap (so long as the rotation angle is 4.715 deg. and the ratio of hex edge length to distance between points is 1:10.53-ish). In the screenshot you’ll notice a small reveal I left between the ‘modules’ to illustrate this.

I’d like to do two things - one, make it so that a list of points can be input at once or in an automated sequence and two, convert the multi-point functionality into a python GH component, with a list of GH-generated points as the input geometry.

I hope this helps! Thanks in advance for your time and thoughts.

Hey nick i can take a look after work.
For now: if you right-click an input node on the ghpython component you can specify the type of Data going in and More importantly for you there is an option for ‘List access’ maybe this will fix your problems


Hi @Nick_Bruscia

did @lando.schumpich’s suggestions help?

Also, in general, if a parameter has “item access” and items are input more than once, the script is repeated to allow the logic to work on each item. You could experiment with this a little in a simpler component.



Giulio Piacentino
for Robert McNeel & Associates

Hi @lando.schumpich and @piac,

Thanks for the hints. Previously, I read some of the online documentation and made sure the Type Hints were set properly for the inputs (Point 3D for points, and float for numeric inputs). However, when I change the Pts input to List Access, I receive this error message:

It seems Item Access is the way to go, so each point can be acted on independently as described by Giulio. I also experimented a bit with a component that tries to input a single point as the original script was intended, but came out with the same results.

PS. here’s the code that’s inside the GH component, in case it’s faster for ya’ll to just look at it here:

import rhinoscriptsyntax as rs
import math

edges = 6
levels = 3
hexGrid = []
work = 2 * math.sqrt((Hex_EL * Hex_EL) - ((Hex_EL / 2) * (Hex_EL / 2)))

def polygon(center,edges,size,angle):
    tempCircle = rs.AddCircle(center,size)
    tempPoints = rs.DivideCurve(tempCircle, edges, create_points=False, return_points=True)
    tempHexago = rs.AddPolyline(tempPoints)
    tempReturn = rs.RotateObject(tempHexago, center, angle, axis=None, copy=False)
    return tempReturn
for i in range(0, levels):
    tempSize = work * (i + 1)
    dut = polygon(Pts, edges, tempSize, 30 + Hex_RA)
    temp = rs.DivideCurve(dut, (i+1) * edges, create_points=False, return_points=True)
for i in range(0, len(hexGrid)):
    polygon(hexGrid[i], edges, Hex_EL, Hex_RA)

1 Like

You’re not actually assigning anything to the output variable ‘a’ of the GhPython component, that’s why it’s displaying nulls.
Also it’s useful to think of rhinoscriptsyntax as adding things to a hidden document, in order to retrieve them you have to assign the GhPython output to the return value of the rs.Add** functions.

e.g. in the last for block:

hexagons = []
for i in range(0, len(hexGrid)):
    hexagon = polygon(hexGrid[i], edges, Hex_EL, Hex_RA))
    # rs.AddPoint(hexGrid[i]) -- not needed

Then set the nicknames of your output parameters to the variables that you’re interested in extracting:


@qythium - thanks! Your tip re: ‘adding things to a hidden document and to retrieve them with rs.Add’ is super helpful. Cheers, n


A post was split to a new topic: Input function question