Rhino can create and manipulate a number of geometric objects, including points, point clouds, curves, surfaces, b-reps, meshes, lights, annotations, and references. Each object in the Rhino document is identified by a globally unique identifier, or UUID, that is generated and assigned to objects when they 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;
}