How to select a subd vertex with python

Hi,
how can I select a subd vertex with python in rhino8?

import Rhino
import rhinoscriptsyntax as rs

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
        
    vertex1 = rs.get?????????

Hi @enzo_molinari,

A sample:

import Rhino

def test_subdvertex_faceat():
    filter = Rhino.DocObjects.ObjectType.MeshVertex
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select subd vertex", False, filter)
    if rc == Rhino.Commands.Result.Success:
        subd = objref.SubD()
        if subd:
            ci = objref.GeometryComponentIndex
            vtx = subd.Vertices.Find(ci.Index)
            if vtx:
                for fi in range(0, vtx.FaceCount):
                    face = vtx.FaceAt(fi)
                    if face:
                        print(face)

if __name__ == "__main__":
    test_subdvertex_faceat()

– Dale

3 Likes

Thank you for your help @dale!

Hi @dale,

i’ve tried your script, slightly changed using GetMultipleObjects or GetObjects and found two problems when SubD vertices are turned on:

  1. it does not show a selection highlight when post selecting
  2. preselection is ignored alltogether
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select SubD Vertices")
    go.EnablePressEnterWhenDonePrompt(True)
    go.GeometryFilter = Rhino.DocObjects.ObjectType.MeshVertex
    go.SubObjectSelect = True
    go.BottomObjectPreference = True
    go.EnableClearObjectsOnEntry(False)
    go.EnableUnselectObjectsOnExit(False)
    go.DeselectAllBeforePostSelect = False
    go.EnablePreSelect(True, True)
    go.GetMultiple(1, 0)

If SubD vertices are turned off, highlighting seems to work. Am i doing this the wrong way ?

thanks,
c.

Hi @clement,

Try using this as a filter.

Rhino.DocObjects.ObjectType.MeshVertex | Rhino.DocObjects.ObjectType.Grip

– Dale

Thank you @dale. I can see the highlight now but have no idea how to get the SubDVertex.Id from a Grip ? Using your example code above, if i select a grip when points are On, i tried to detect that and query for:

objref.GeometryComponentIndex.ComponentIndexType

which returns an “InvalidType”. If i try to get the index of the grip like this:

objref.GeometryComponentIndex.Index

it is always -1. Is there a reason why there is no dedicated filter vor SubDVertex ?

_
c.