Python Grasshopper


is there a way to figure out how to find out the equivalent of a grasshopper command in python grasshopper ? for example id like to make a curve, which is found under CURVE/PRIMITIVE/LINE SDL, this takes a starting point, a vector and length to form a ray like line.

is there a way to figure these command out ? do I need to import a library ( pretty sure I do need to )

thanks in advance!

Hi Hakam,

Sometimes there is no direct function which will output the same result as a Grasshopper component. In those cases, Grasshopper component actually uses a couple of them, to generate the results.
Check the attached file below. (9.5 KB)

Hi djordje,

thank you a lot for your reply, I used the rhinocommon command Line

1 Like

HI @Hakam_ElMajed,

You can alternatively use rhinoscriptsyntax/RhinoScript, RhinoCommon/import Rhino or ghpythonlib/NodeInCode:

import rhinoscriptsyntax as rs  #RhinoScript

#dir can be a tuple, a Point3d or a Vector3d
scaled = rs.VectorScale(dir, length)
#start can be a Point3d, a tuple or a Vector3d
a = rs.AddLine(start, start + scaled)
import Rhino  #RhinoCommon

#start needs to be a Point3d, direction a Vector3d, and length a float
a = Rhino.Geometry.Line(start, direction, length)
import ghpythonlib.components as ghc  #ghpythonlib/NodeInCode

#anything that works in GH will work (but not RhinoScript Guids/uuids):
a = ghc.LineSDL(start, direction, length)

If the variables are inputs from the outside, you can name them as the component inputs. Also, you can choose ‘Type Hints’ for each input. Just right-click on inputs.

See also the component Help, by right-clicking on the component icon and choosing Help.