Get; Set; Control Points / Grips with Python

How can we Get/Set a property using Python, for example data such as ControlPoint Rhino.Geometry.ControlPoint. C# and VB has the ( get; set; ) example, but I can’t see if there’s an equivalent way to do this in Python?

import Rhino.Geometry as rg

xCoordinate = pt.X #pt is point3d object
pt.X = 10;

It differs quite a bit depending on the specific geometry type. For instance, the NurbsCurve class has the Points property, which returns a NurbsCurvePointList. From which you can get/set an Item

1 Like

Thanks Lukas + Anders. I’ll post my example here to save double posting.

I have a blue curve and cyan curve in the attached file. The blue curve is a MorphControl for the surface. Both curves have the same structure.I want to amend XY locations of each point on the blue curve to the XY locations of the Cyan curve, for each associated control point. Below is my isolated example.

set_points_example.3dm (143.7 KB)

NB This is a simplified example, that I want to translate to doing a CageEdit: Local to a polysurface

This is what I have so far. I can set the location of the control point, but it doesn’t actually seem to redraw and make the change. I would appreciate any ideas on how to approach this differently and correctly.

# Match Control Point Locations
# V1.0
# Designed for matching control points of a Control cage to a target location
#Matching XY locations

import rhinoscriptsyntax as rs
import Rhino as rh
import scriptcontext as sc

#My Test Target Location for Setting Point [0]
target_location = rs.CreatePoint(-342,79,52)

#Pick MorphControlType
source_guid = rs.GetObject("Pick Morph Control with points to transform", filter = 131072)
source_object = rs.coercerhinoobject(source_guid)
morphcontrol_curve = source_object.Geometry.Curve

print "Location Before:", morphcontrol_curve.Points [0].Location

points_list = morphcontrol_curve.Points
result = points_list.SetPoint(0, target_location)

if result:
    print "Location was changed behind the curtain"

print "Location After:", morphcontrol_curve.Points [0].Location

#Rhino.Geometry.Transform.Translation() # between each original/offset point

# Rhino.Geometry.Collections.NurbsCurvePointList.SetPoint(0, target_location)
"""
rs.AddPoint(morphcontrol_curve.Points [0].Location)
rs.AddPoint(morphcontrol_curve.Points [1].Location)
"""

# Maybe can just use Replace?
# Maybe transform points? sc.doc.Objects.Transform()
# Eventually match all points on a curve as below
# target = rs.GetObject( "Pick curve to match to", filter = 4 )

I tried using:

points_list.Item()
and
points_list.Item(0, (5,5,5))

I got:
Message: indexer# is not callable

printing points_list.Item got me

<indexer# object at 0x000000000000004E>

where points_list is a Rhino.Geometry.Collections.NurbsCurvePointList object.

You use square brackets to access the item (e.g. myCurve.Points.Item[Index]). I forgot about this method though, which is probably more appropriate here:

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Collections_NurbsCurvePointList_SetPoint.htm

Yeah that’s what I tried here. Although I don’t know if I need some script context or redraw for that change to actually be reflected in the viewport. Maybe it’s immutable? My script shows me the point location before and after setting, but doesn’t update.

I still wouldn’t know how to set a point with the Item property - although I can get the Geometry.ControlPoint out fine now - thank you.

Ah yes, so you did. My bad :slight_smile:

I pretty much only Rhino code within Grasshopper, so I won’t be much help. But yes, I believe you must update/replace the curve geometry within the Rhino document, and then call redraw.

Thank you still though, Anders. I am thinking that because it’s a MorphControl object, maybe it is an exception. I don’t get access to the standard rs. curve stuff such as the CP / grip style functions for the control morph object.

I think Cage Edit used to work so that you could:

Set a curve as a control
explode it
Manipulate it
Set it as the cage again, and the difference between the explosion would be manipulated

And it would update. But I’m unsure.

 |          Replace(self: ObjectTable, objref: ObjRef, newObject: RhinoObject) -> bool
 |          
 |              Replaces one object with another. Conceptually, this function is the same as 
 |               calling
 |                      Setting new_object attributes = old_object attributes
 |              
 |                       DeleteObject(old_object);
 |                      AddObject(old_object);
 |          
 |          
 |              objref: reference to old object to be replaced. The objref.Object() will be deleted.
 |              newObject: new replacement object - must not be in document.
 |              Returns: true if successful.

@Jonathan_Hutchinson1 have you seen Dale’s example here?

Hi David,

Thank you - Pascal Golay helped me with this on another sample. I mentioned that I overlooked the grips because I thought the MorphControl type wouldn’t inherit those properties etc.

deform_points

From the gif it doesn’t look like much, granted…

Dear Jonathan Thank you for this valuable help.

I tried the code it worked very well but in my case, the code moving


closest point results wrong place. I tried to limit the translation only for example Y axis but I’m still babying on scripting so couldnt done.