Select newly baked object by ghpython

hi, everyone. m new to ghpython, and trying to bake some geometry to rhino with attributes.
after baking ,i want to select the newly baked objects. but i have no idea how to do that.
please give me some advices.
here is my bake code:

if bake:
    geo = geometry
    attr = Rhino.DocObjects.ObjectAttributes()
    attr.SetUserString(key,value)
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    obj_id = sc.doc.Objects.Add(geo,attr)

m using a button to trigger the baking , after click the bake button, bake = False, so i can not pass the “obj_id” out for further use.
i konw i could bake it to a layer, and select it by layerName. but there are other objects on that layer.
neither by the userString.


I guess You are looking for ObjectTable.Select Method:

import Rhino
doc = Rhino.RhinoDoc.ActiveDoc
if bake:
    geo = geometry
    attr = Rhino.DocObjects.ObjectAttributes()
    attr.SetUserString(key,value)
    id = doc.Objects.Add(geo,attr)
    doc.Objects.Select(id)

Bake.gh (7.5 KB)

3 Likes

thanks for your reply. and I also need to get the object bake to grasshopper. something like this.
image

You mean something like this?

import Rhino
doc = Rhino.RhinoDoc.ActiveDoc
if bake:
    geo = geometry
    attr = Rhino.DocObjects.ObjectAttributes()
    attr.SetUserString(key,value)
    guid = doc.Objects.Add(geo,attr)
    doc.Objects.Select(guid)
if 'guid' in globals():
    a = guid

Bake.gh (8.9 KB)

2 Likes