Highlighting SubObject

Using Python script.

Do I have to call sc.doc.Objects.UnselectAll() when highlighting a subobject within a polycurve? The following code will not highlight the first subobject in the polycurve unless I call UnselectAll. I also tried calling Rhino.Input.Custom.GetObject.EnableHighlight(False) hoping the HighlightSubObject call would work.

I noticed if I use rs.GetObject() the subobject is highlighted, so I stepped through rhinoscript (selection.py) and noticed it calls scriptcontext.doc.Objects.UnselectAll(). Must his method be called or is there some property or method in the GetObject class that can be set so that I don’t have to call UnselectAll? Setting a property is a bit more cleaner in my opinion rather than going outside the class.

def HighlightFirstSubCurve():
    filter = Rhino.DocObjects.ObjectType.Curve
    
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt('Get polycurve.')
    go.GeometryFilter = filter
    go.EnablePreSelect(False, True)
    go.DeselectAllBeforePostSelect = False
    #go.EnableHighlight(False)
    go.Get()
    rc = go.CommandResult()
    if rc != Rhino.Commands.Result.Success:
        return
    obj = go.Object(0).ObjectId
    print str(obj)

    #sc.doc.Objects.UnselectAll()
    
    rhObj = sc.doc.Objects.Find(obj)
    
    if not isinstance(rhObj.Geometry, Rhino.Geometry.PolyCurve):
        print 'User did not select a polycurve.'
    
    ci = Rhino.Geometry.ComponentIndex(Rhino.Geometry.ComponentIndexType.PolycurveSegment, 0)
    rhObj.HighlightSubObject(ci, True)
    sc.doc.Views.Redraw()
    

if __name__ == '__main__':
    HighlightFirstSubCurve()

Hi @Mike24,

Without unselecting what you just selected, what would you expect to see?

– Dale

@dale - I gottcha. I thought maybe the code behind the scenes would do it automatically. Thanks for the feedback.