How to write to move selected control points onto nearest surface


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


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)


if __name__=="__main__":

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:


1 Like

Hi clement,
Thank you !!

Thank you for your help. Does the code could support modeling history? For example, if I want to adjust the shape of the nearest curve or surface, the moving points will update automatically, similar to the history.

If the grips you are moving belong to an object that was used as input to a history-support command, then yes.

– Dale

No, it is not used as an input to history support commands. I wonder if the Rhino SDK can do this?

Hi @dale
Can you elaborate a bit what you have in mind or how that might work?
Thanks, Jess

Hi @Jess,

Rhino’s history is command based. History-supporting commands record the input that produces an output. When the input changes (perhaps by using a script) then the output is regenerated by replaying the command.

Hope this helps.

– Dale

Thanks @dale ,
Yes, I’m aware of Rhino’s history. I misinterpreted the question and your answer…