How to write to move selected control points onto nearest surface


#1

Hi,

I’d like to know how to write to move selected control points onto nearest surface or curve by Python.

Thanks.


#2

Hi Katsu, not shure if it works in all cases but try:

import rhinoscriptsyntax as rs
import scriptcontext as sc

def PullGripsToClosest():

    grips = rs.GetObjectGrips("Select grips", True, True)
    if not grips: return

    objs = rs.ObjectsByType(4+8, select=False, state=1+2)
    if not objs: return

    for g in grips:
        # remove objects having grips selected from 
        # the list of objects allowed to pull to
        if g[0] in objs: objs.remove(g[0])

        obj, close_pt = rs.PointClosestObject(g[2], objs)
        if obj: rs.ObjectGripLocation(g[0], g[1], close_pt)

    sc.doc.Views.Redraw()

if __name__=="__main__":
    PullGripsToClosest()

Note: you can select controlpoints of surfaces or curves and it will pull them to the closest surface or curve. Depends on what is closer. It will not pull to itself :wink:

c.


#3

Hi clement,
Thank you !!