Moving grips with python

Hello all,

I’m rather new to python and rhino scripting, please bear with me.

I want to let the user select and move any type of object including grip in a certain direction, using python. I figured that rs.GetObjects ignores grips, so I’m doing the objects input like this :

objs = rs.GetObjects( "my-prompt", filter=2013524799, preselect=True )

Where 2013524799 is a bitwise OR of all the geometry filters.
So in objs I successfully have any type of objects including grips. I want to translate each of these objects, but if I move them like this :

for obj in objs:
    rs.MoveObject( obj, vector )

points, curves and surfaces are moved properly but grips are ignored. What is the reason for that ? Is there anything I can do using rhinoscriptsyntax ? It would have been a breeze…

Digging for a workaround I’ve read this related post from Dale Fugier. However I had a rough time with this solution, because I want to move the grips and redraw at runtime. scriptcontext.doc.Objects.GripUpdate will update the grip, but either I set its deleteOriginal argument to False and the objects are duplicated many times along the translation, either I set it to True, and nothing happen, I assume because the grip is removed from the TransformObjectList. I tried to add the new object returned by GripUpdate to the TransformObjectList, but it doesn’t seem to work.

Is there an easier solution to move grips at runtime with python ? If not I will revert to trying to adapt @dale solution, but I’s been a few hours I struggled with this already…

Hi Felix,

The rhinoscriptsyntax.MoveObject method only moves top-level objects. Grips are a different deal, thus the sample I put together.

I am not sure what you mean by “at runtime”. Isn’t that what my samples does?

Perhaps we need a more details on what you want, and why?


– Dale

Hi Dave, thank you for your reply.

By “at runtime” I mean that I want the grips to move while the user is picking an end point for the translation, and the geometry updated progressively.

I wanted to code a set of functions to transform objects parallel to the target plane ( pan parallel to the target plane, rotate parallel to the target plane… ). This to make easier the editing of geometries in perspective view. I finally solved my problem with this function :

def panObjs( newPoint ):

        global startPoint

        # move non-grip objects
        for obj in objs:
            rs.MoveObject( obj, newPoint - startPoint )

        # move grip objects
        for grip in grips:
            gripObj = sc.doc.Objects.Find( grip )
            if gripObj:
                gripObj.Move( newPoint - startPoint )

        # get list of selected grip owners
        owners = []
        for grip in grips:
            gripObj = sc.doc.Objects.Find( grip )
            if gripObj:
                owners.append( gripObj.OwnerId )

        # remove duplicates from owners
        owners = list( set( owners ) )

        # update owners
        for ownerId in owners:
            ownerObj = sc.doc.Objects.Find( ownerId )
            ownerGrips = ownerObj.GetGrips()
            indexes = [] # grip indexes under update
            for ownerGrip in ownerGrips:
                if ownerGrip.Id in grips:
                    indexes.append( ownerGrip.Index )
                    grips.remove( ownerGrip.Id )
            ownerObj = sc.doc.Objects.Find( ownerId )
            newOwner = sc.doc.Objects.GripUpdate( ownerObj, True )
            ownerObj = newOwner or ownerObj
            newGrips = ownerObj.GetGrips()
            for index in indexes:
                grips.append( newGrips[ index ].Id )

        startPoint = newPoint

I call this in a custom Rhino.Input.Custom.GetPoint.OnDynamicDraw. I don’t know if it’s optimal, and it doesn’t seem to handle SubD geometries.

Hi @felix.mariotto,

See if the following script is of any help. (1.9 KB)

– Dale

1 Like