Can't edit subd vertices using python

Hi,

I am attempting to modify the coordinates of a subd vertex using python. I thought that editing the vertex ControlNetPoint would work (docs say it has both a setter and getter), but the subd does not change. Am I doing something wrong? Code posted below.

Also, it would great to be able to edit the vertex surface point directly rather than the control point. I see that vert.SurfacePoint() returns a Point3d object, but not sure if this is editable or not. Is it possible to edit the surface point directly?

import Rhino

def edit_subd_verts():
    filter = Rhino.DocObjects.ObjectType.SubD
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select SubD", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: return
    
    subd = objref.SubD()
    if not subd: return
        
    vert = subd.Vertices.First
    print(vert.ControlNetPoint)
    vert.ControlNetPoint.X = 30.0 # This has no effect
    
edit_subd_verts()

I am currently using Rhino 7 SR12 2021-11-9 on Windows 10.

Cheers,
Michael

I think this is not possible, but you can work with Grips or work with the control mesh instead, move the vertices, convert to subd and delete the old subd.

vert.ControlNetPoint.X = 30.0 gets the value of the control point location (copies it to a temporary Point3d) and sets the X property of that value to 30. For this to work like you want, SubDVertex.ControlNetPoint would need to be able to deal with a reference to the control point; I don’t think we have a safe way to do that.

Instead you can set the vert.ControlNetPoint property to a new Point3d:

import Rhino

def edit_subd_verts():
    filter = Rhino.DocObjects.ObjectType.SubD
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select SubD", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: return
    
    subd = objref.SubD()
    if not subd: return
        
    vert = subd.Vertices.First
    print(vert.ControlNetPoint)
    cnp = vert.ControlNetPoint
    cnp.X = 30
    vert.ControlNetPoint = cnp
    print(vert.ControlNetPoint)
    Rhino.RhinoDoc.ActiveDoc.Objects.AddSubD(subd)

Setting surface point locations hasn’t made its way to RhinoCommon yet, it’s being tracked there: RH-59542 Allow for getting and setting SubD “edit” points using RhinoCommon.

3 Likes

Thanks Pierre. That does indeed modify the coordinates.

Importantly I was missing Rhino.RhinoDoc.ActiveDoc.Objects.AddSubD(subd) because I thought I could modify the subd inplace without creating a copy.

Looking forward to being able to modify the surface point locations directly.

Cheers,
Michael

Hi,

One year later, is still impossible to modify vertices (subd point) with Python directly?
What’s about Rhino8?

Thanks

Hi @Pierrafee ,

Sorry this thread got forgotten. There is a C# sample available to modify edit points in a SubD:

A Python version could use all the same RhinoCommon methods.

The caveat is that it will interpolate all limit surface points of the SubD at the same time, without any control on fixed control points. RhinoCommon access to an interpolator with more granular control is work that we plan to do during the Rhino 8 release cycle and tracked at the link I posted before: RH-59542 Allow for getting and setting SubD “edit” points using RhinoCommon.

2 Likes

RH-76637 is fixed in the latest WIP