How to test an object is Rhino object or T-Splines object using RhinoCommon

Hi,
How to test an object is Rhino object or T-Splines object using RhinoCommon?

I’m not sure this is going to be that easy, as T-Splines objects masquerade as Breps with custom user data.

@tomfinnigan might be able to help here…

So I took a look, but I’m not sure how to do it in RhinoCommon.

The GUID is 10D2CFF0-8191-4CC7-AFDF-D8FAF16E2120

In C++, I’d do something like:

CRhinoObject* obj = ...; // from somewhere
ON_UUID ts_id = { 0x10d2cff0, 0x8191, 0x4cc7, { 0xaf, 0xdf, 0xd8, 0xfa, 0xf1, 0x6e, 0x21, 0x20 } };
bool is_tspline = (obj->Geometry()->GetUserData( ts_id ) != NULL);

With better error checking, of course.

However, I’m not sure how to do this in C#/RhinoCommon.

Maybe something like obj.Geometry.UserData.Find? Not sure.

UserDataList.Find works by supplying it with a .NET Type. Finding TS data is not going to work in RhinoCommon.

As RhinoCommon is a .NET layer on Rhino C++, I would create a C++ DLL that has exported function(s) for checking the TS Guid-based UserData, using the IntPtr for the RhinoObject obtained from Rhino.Runtime.Interop.NativeGeometryConstPointer (see http://4.rhino3d.com/5/rhinocommon/html/M_Rhino_Runtime_Interop_NativeGeometryConstPointer.htm)

Has anyone been able to do this using C# only? I too need to know if a Rhino GripObject is in fact a TSplines Vertex/Face/Edge/Surface…

Any help is appreciated.

I’m not see any way of doing this from RhinoCommon.

UserData.Find will find your own data. But there needs to be some kind of “Exists” method that you can pass a GUID and get a true or false in return. I’ll get this on the to-do list.

Thanks Dale! Knowing whether it had TSpline UserData at all may be enough for me to differentiate it from a standard grip object. Look forward to seeing what you come up with.

If you like to p/invoke, export the following function from C++ and wrap it for C#:

bool ObjectHasTSplineUserData(const CRhinoObject* object)
{
  // 10D2CFF0-8191-4CC7-AFDF-D8FAF16E2120
  static const GUID TSplineUserData_GUID =
    { 0x10d2cff0, 0x8191, 0x4cc7, { 0xaf, 0xdf, 0xd8, 0xfa, 0xf1, 0x6e, 0x21, 0x20 } };

  ON_UserData* userdata = nullptr;
  if (nullptr != object)
  {
    const ON_Geometry* geometry = object->Geometry();
    if (nullptr != geometry)
      userdata = geometry->GetUserData(TSplineUserData_GUID);
    if (nullptr == userdata)
      userdata = object->Attributes().GetUserData(TSplineUserData_GUID);
  }
  return (nullptr != userdata);
}