Select point on a vector

python

#1

Hi,

I cannot find the way how to select a point on a given vector or a line. I would like to select and visualize the point on a line. Should I use projection. Is there a method for this?

(I already find how to visualize it by dynamic display)

Thanks,


GetPointOnCurve extend cursor distance
(Lando Schumpich) #2

Hey not sure what you mean with point on vector but there is a method for picking a point in the rhino docs:

import rhinoscriptsyntax as rs

obj = rs.GetObject("Pick a curve")

if rs.IsCurve(obj):

    point = rs.GetPointOnCurve(obj, "Point on curve")
    if point: rs.AddPoint(point)

#3

I thought it is something, more complicated.

Thanks Lando!


#4

Here is a RhinoCommon equivalent of the Rhinoscript method “GetPointOnLIne”, which is not yet implemented in python rhinoscriptsyntax…

import rhinoscriptsyntax as rs
import Rhino

def GetPointOnLine(prompt,ptA,ptB,track):
    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt(prompt)
    gp.Constrain(Rhino.Geometry.Line(ptA,ptB))
    gp.EnableDrawLineFromPoint(track)
    get_rc = gp.Get()
    if get_rc==Rhino.Input.GetResult.Point: return gp.Point()

def TestFunction():
    msg1="Pick point on line"
    line_start=rs.coerce3dpoint([0,0,0])
    line_end=rs.coerce3dpoint([1,1,0])
    result=GetPointOnLine(msg1,line_start,line_end,True)
    if result: rs.AddPoint(result)
TestFunction()

#5

Thank you Helvetosaur.

This is a nice example. It makes more sense to understand IronPython.