Site Tools

How to Get an Object's UUID

C++, .NET

Summary: Demonstrates how to get an object's UUID using the Rhino SDK.
Notice: The Rhino.NET SDK is deprecated in Rhino 5. An example adapted for the new RhinoCommon SDK is here.

Rhino can create and manipulate many geometric objects, including points, point clouds, curves, surfaces, b-reps, meshes, lights, annotations, and references. A globally unique identifier, or UUID, is assigned to each object in the Rhino document when the objects are created. Because identifiers are saved in the 3DM file, an object's identifier will be the same between editing sessions.


The following code sample demonstrates how to obtain an object's unique identifier, or UUID, using the Rhino SDK.


CRhinoCommand::result CCommandTestID::RunCommand(const CRhinoCommandContext& context)
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select object" );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();
  const CRhinoObjRef& ref = go.Object( 0 );
  const CRhinoObject* obj = ref.Object();
  if( !obj )
    return CRhinoCommand::failure;
  ON_UUID uuid = obj->Attributes().m_uuid;
  ON_wString str;
  ON_UuidToString( uuid, str );
  ::RhinoApp().Print( L"The object's unique identifier is \"%s\".\n", str );
  return CRhinoCommand::success;


Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
  As IRhinoCommand.result
  Dim go As New MRhinoGetObject
  go.SetCommandPrompt("Select object")
  go.GetObjects(1, 1)
  If (go.CommandResult() <> IRhinoCommand.result.success) Then
    Return go.CommandResult()
  End If
  Dim ref As IRhinoObjRef = go.Object(0)
  Dim obj As IRhinoObject = ref.Object()
  If (obj Is Nothing) Then Return IRhinoCommand.result.failure
  Dim uuid As Guid = obj.Attributes().m_uuid
  RhUtil.RhinoApp().Print("The object's unique id is " + uuid.ToString() + vbCrLf)
  Return IRhinoCommand.result.success
End Function


public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  MRhinoGetObject go = new MRhinoGetObject();
  go.SetCommandPrompt("Select object");
  go.GetObjects(1, 1);
  if(go.CommandResult() != IRhinoCommand.result.success)
    return go.CommandResult();
  IRhinoObjRef objref = go.Object(0);
  IRhinoObject obj = objref.Object();
  if(obj == null)
    return IRhinoCommand.result.failure;
  System.Guid uuid = obj.Attributes().m_uuid;
  RhUtil.RhinoApp().Print("The object's unique id is " + uuid.ToString() + "\n");
  return IRhinoCommand.result.success;
developer/sdksamples/getuuid.txt ยท Last modified: 2020/08/14 (external edit)