Python: Control Surface Grips Enable [SOLVED]

Hi, I’m new here.

I’m trying to write a python script in grasshopper that will taking in a surface, rebuild it and then:

  1. Enable the surface’s control points / grip points
  2. Access and edit individual grip points.
  3. Replace those points, updating the surface and disabling the points again.

Here is the Code:
import rhinoscriptsyntax as rs

#Enable Surface Grips (Control Points)
Modify_Surface = rs.EnableObjectGrips(Surface_In, True)

#Function Definition To Move Grip Point (Control Point)
def Change_Point_Location(Surface, Index, Move_X, Move_Y, Move_Z):
    Point = rs.ObjectGripLocation(Surface, Index)
    Point[0] += Move_X
    Point[1] += Move_Y
    Point[2] += Move_Z, Index, Point)

#Change Points
Change_Point_Location(Modify_Surface, 0 , 10, 10 , 10)

#Disable Surface Grips (Control Points)
Modify_Surface = rs.EnableObjectGrips(Surface_In, False)

Surface_Out = Modify_Surface

I have an issue when calling the function at #Change Points as I get a GUID error:

Runtime error (TypeErrorException): Parameter must be a Guid or string representing a Guid

line 890, in coerceguid, “C:\Users\xxx\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\”
line 1062, in coercerhinoobject, “C:\Users\xxxx\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\”
line 195, in ObjectGripLocation, “C:\Users\xxxx\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\”
line 11, in Change_Point_Location, “”
line 18, in script

You have this:

Modify_Surface = rs.EnableObjectGrips(Surface_In, True)

rs.EnableObjectGrips returns a boolean, not the surface GUID

So when you pass that to Change_Point_Location, it fails…

Note you also have a typo here:


Thanks, I hadn’t realized that.
I am looking into rs.EnableObjectGrips and it is returning None
Using the following command: rs.EnableObjectGrips(Surface_In, True)

Would you be able to show me how to get this working? (Surface_In is the surface from the ghpython input)

You should specify Grasshopper if you are working on scripts inside GH or put them in the Grasshopper section (if you did originally I missed it sorry). There is a difference between running a script in the native Rhino interface versus from the Grasshopper component. Object grips are properties of the surface object in the Rhino document, whereas the surface referenced by the GH component is ‘virtual’ - it is just geometry. EnableObjectGrips expects a GUID from the Rhino document I think… I have no idea how to manipulate the control points of a GH surface or of a surface in the Rhino document from GH - maybe there is a plug-in that allows that. Someone else might know.

I’m changing the category of this to Grasshopper, maybe you will get a better response that way.

Thanks (I mentioned it at the beginning of the op) :slight_smile:
I think I actually need to use the Rhino Common Library as I probably need access to more than just the functions in rhino script synthax. I’ll look into it and post a solution if I find it.

Solution is to use Rhino Common Library

  1. Transform Surface to NurbsSurface
  2. Rebuild adding Control Points (U_Count and V_Count)
  3. Get Point List
  4. Get Point
  5. Modify Point
  6. Set Point

import Rhino.Geometry as rg

#Convert to Nurbs Surface
Nurbs_Surface = Surface_In.ToNurbsSurface()

#Rebuild Surface
Rebuilt_Surface = Nurbs_Surface.Rebuild(3,3, U_Count, V_Count)

#Get Control Points
Control_Points = Rebuilt_Surface.Points

#Select Point at U,V Index 0,0
Point = Control_Points.GetControlPoint(0,0)

#Move Point X, Y, Z
Point.X -= 1
Point.Y += 1
Point.Z -= 2

#Set Control Point

#Output Final Surface
Surface_Out = Rebuilt_Surface

To save time here is a handy function I made for changing control points with one line:

def Move_Control_Point(Control_Points_List, U, V, X, Y, Z):
#Select Point at U,V Index 0,0
Control_Point = Control_Points_List.GetControlPoint(U,V)

#Move Point X, Y, Z
Control_Point.X += X
Control_Point.Y += Y
Control_Point.Z += Z

#Set Control Point

#Move The Point at U = 0 and V = 0 by X + 3, Y + 3, Z + 3
Move_Control_Point(Control_Points, 0, 0, 3, 3, 3)

#Move The Point at U = 4 and V = 0 by X + 0, Y + 4, Z + 0
Move_Control_Point(Control_Points, 4, 0, 0, 4, 0)

Have you looked at Grasshoppers Point Deform component by any chance? It does this.

I did, but it wasn’t efficient when it came to moving multiple points in various directions/distances.

What do you mean by efficient? Seems to work well here (just used some random vector directions and lengths) (13.1 KB)


Oh, I didn’t realize you could do it like that, thanks :slight_smile:
I’ve got most of the python script working now which makes it a lot more manageable now as I can move entire columns and rows.
However I am struggling to find a solution to set the weight of the control points. Is there a grasshopper component for that? I haven’t found anything yet

However I am struggling to find a solution to set the weight of the control points.

1 Like

Yeah, I’ve been using that but it seems to move the location of the control point too. I opened a separate post on it here: GHPython: Setting the weight of a surface control point changes the location of the point