Get the index of a BREP vertex in Rhinocommon

Hi all,
I’m really new to Python/Rhinocommon and I’m trying to get the index of a BREP vertex by picking it. I’ve already this code, but it only returns the index of the edge where the point is picked.

    import rhinoscriptsyntax as rs
    import Rhino
    import scriptcontext as sc


    def GetBrepVertexIndex():

        gp = Rhino.Input.Custom.GetPoint()
        gp.SetCommandPrompt("Pick point")
        gp.Get()
        if gp.CommandResult() <> Rhino.Commands.Result.Success:
            return gp.CommandResult()
        brep = gp.PointOnObject()

        print brep.ObjectId
        print brep.GeometryComponentIndex.ComponentIndexType
        print brep.GeometryComponentIndex.Index

    GetBrepVertexIndex()

Is there any way to get this information?

Many thanks in advance?

Hi Jeffoulet,

How about this:

import rhinoscriptsyntax as rs
import Rhino

def GetGrip():
    
    #get a object grip (controlpoint, vertex)
    grip = rs.GetObjectGrip('get vertex')
    
    # make sure it's a brep vertex
    if not rs.IsBrep(grip[0]):
        print 'selected vertex does not belong to a brep'
        return
    
    # get brep geomrtry and vertex index
    brep = rs.coercebrep(grip[0])
    index = grip[1]
    
    #get vertex on brep
    vertex = brep.Vertices[index]
    #create dot as a debig test
    
    rs.AddTextDot('X',vertex.Location)
    

GetGrip()

Does that makes sense ?

HTH
-Willem

Hi Willem,

I tried your solution and it works pretty well. I didn’t think to use the control points :slightly_smiling:

Many thanks!

1 Like