I was looking for this or a similar request on the forum but did not find it.
I would love to see if you implemented Layers function which helps us identify the location of the object selected in the viewport in the Layers tree. You already have the option to select an object via the Layers tree and it gets selected in the viewport.
import rhinoscriptsyntax as rs
import scriptcontext as sc
obj_ids = rs.GetObjects('Select objects')
indices = []
for obj_id in obj_ids:
layer = rs.ObjectLayer(obj_id)
indices.append(sc.doc.Layers.FindName(layer).Index)
sc.doc.Layers.Select(indices, True)