Selecting SubObject Grips

Using Python script.

I know how to get and select the grips of an object, but how do I get and select the grips of a subobject. I tried using the RhinoObject.GetSubObjects(), turning grips on for the first subobject, getting the grips for the first subobject, and then using Select for the first grip of the first subobject. I’m getting the following error message back:

This object cannot be modified because it is controlled by a document.

I would like to select the first and last grip of the first subobject. How do I do this?

Here is the code. SelectPolyCurveStartAndEndGrips works great in selecting the first and last grips of the polycurve, but SelectPolyCurveStartStartSegmentStartAndEndGrips does not select the first and last grips of the first segment.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry as rg

def isPolyCurve(rhObject, geometry, componentIndex):
    return isinstance(geometry, rg.PolyCurve)

def SelectPolyCurveStartAndEndGrips():
    pc = rs.GetObject('Select polycurve.', custom_filter=isPolyCurve)
    print pc
    
    sc.doc.Objects.UnselectAll()

    rhObj = sc.doc.Objects.Find(pc)
    rhObj.GripsOn = True
    grips = rhObj.GetGrips()
    grips[0].Select(True, True)
    grips[len(grips) - 1].Select(True, True)
    sc.doc.Views.Redraw()

def SelectPolyCurveStartStartSegmentStartAndEndGrips():
    pc = rs.GetObject('Select polycurve.', custom_filter=isPolyCurve)
    print pc
    
    sc.doc.Objects.UnselectAll()

    rhObj = sc.doc.Objects.Find(pc)
    subObjs = rhObj.GetSubObjects()
    firstSubObj = subObjs[0]
    firstSubObj.GripsOn = True
    grips = firstSubObj.GetGrips()
    grips[0].Select(True, True)
    grips[len(grips) - 1].Select(True, True)
    sc.doc.Views.Redraw()

if __name__ == '__main__':
    #SelectPolyCurveStartAndEndGrips()
    SelectPolyCurveStartStartSegmentStartAndEndGrips()

I can accomplish what I want to if I can get the RhinoObject of the subobject. Is this possible? The only way I have accessed a RhinoObject before is by sc.doc.Objects.Find() which requires the GUID and the subobjects do not have GUIDs that I know of.

I also noticed that when examining the grips of the subobject, they are all disposed and IsDocumentControlled is True. This is causing the original error. I still need to figure out how to select the start and end grips of the subobject.

Any ideas?

I thought maybe the only way to do this is iterate through all the subobjects and if it’s a curve then get the number of points. If it’s a line then the number of points is 2. Then figure out what the first and last points (grips) are for the segment I want to select the first and last grip. Is this the BEST way to go about this or is there an easier way?

The number of grips are the same as the number of points for curves, correct?

Hi @Mike24,

This is not possible, as technically there is no such thing as a sub-object.

A RhinoObject reference geometry. And Rhino objects can have grips that you can turn on to manipulate the geometry.

Some Rhino objects allows you to select components of the geometry. For example, by pressing Ctrl+Shift,you can select a segment of a PolyCurve. The results of the selection are available in the returned ObjRef.

RhinoObject.GetSubObjects explodes a Rhino object into component pieces. The result are retuned as an array of Rhino objects, which contain both the (component) geometry and attributes (color, layer, etc.) for convenience. To fully use the results, you’ll need to add the Rhino objects to the document using ObjectTable.AddRhinoObject.

Hope this helps.

– Dale