How to create "Grasshopper Line SDL" using rhinoscriptsyntax?

How to create Grasshopper Line SDL using rhinoscriptsyntax?

by :
Start point
Direction
Length

Here’s one way:

import rhinoscriptsyntax as rs

s = 0,0,0
d = [1,1,0]
l = 5

vec = rs.VectorScale(rs.VectorUnitize(d),l)

rs.AddLine(s, rs.PointAdd(s, vec))

-Kevin

1 Like

In Grasshopper, using the RhinoCommon is perferrable.

import Rhino.Geometry as rg


def create_line(start, direction, length):
    vec = direction
    vec.Unitize()
    return rg.Line(start, start + vec * length)


if __name__ == "__main__":
     s = rg.Point3d(0, 0, 0)
     d = rg.Vector3d(1, 1, 0)
     l = 5.0

     a = create_line(s, d, l)
1 Like

Indeed, and fully skipping middlemen, there’s also the overload that takes start, direction and length directly:

3 Likes

Thank you all.

import Rhino.Geometry as rg
rg.Line(Point3d, Vector3d, length) works just fine.

Function approach is interesting. Why in Grasshopper RhinoCommon is preferable and when rhinoscriptsyntax used?

rhinoscriptsyntax was meant for scripting in Rhino and often introduces some confusion when used in GHPython, like for instance having to deal with GUIDs (unique references) instead of geometry objects directly.