Get a new object GUID that is not yet used by the document

Hi,

Is there a way to get a new RhinoObject GUID that is not yet used by the Rhino document?

My goal is to assign a GUID to an object before it is beeing added to the document. I think it should be possible as this says:
https://developer.rhino3d.com/api/rhinocommon/rhino.docobjects.objectattributes/objectid?version=8.x
“If the value is not Guid.Empty and it is not used by another object in the model, then that value persists.”

Thanks

Hum I am actually not very confident with GUID, but it seems that calling Guid.NewGuid() is sufficently safe for getting a new GUID which is not used yet by Rhino (or anything else)…

Can someone confirm or infirm this asumption?

1 Like

Hi @Ludovic,

Yes, you can assign your own GUID if you want. Or, you can just obtain (and store) what is returned.

import Rhino
import scriptcontext as sc
import System

def Test():
    plane = Rhino.Geometry.Plane.WorldXY
    circle = Rhino.Geometry.Circle(plane, 5.0)
    curve = Rhino.Geometry.ArcCurve(circle)
    
    attributes = sc.doc.CreateDefaultAttributes()
    attributes.ObjectId = System.Guid.NewGuid()
    print(attributes.ObjectId.ToString())
    
    id = sc.doc.Objects.AddCurve(curve, attributes)
    if id:
        print(id.ToString())
        
    sc.doc.Views.Redraw()

if __name__ == "__main__":    
    Test()

– Dale

2 Likes

Great, thanks Dale.