Updating UserData when all I have is an item of that data

I have a gridview in which I display records for editing. Once complete, I want the “go” button to update not only the underlying database, but also the blocks represented by the rows in the gridview.

More specifically, each row has a field “ID” and each block has a field “ID”. Without the user having to select the blocks, I’d like the plugin to locate the appropriate block and update its UserData, as well as updating the corresponding row in the database.

I already have the code in place to update the database, but I’m stumped on getting the instance, itself.

I’ve been wrestling with this for a week.

TIA

If you are tracking instance objects by their object guid, then you can use RhinoDoc.Objects.Find to retrieve it. For example:

Guid object_id = <some object guid>;

RhinoObject rhino_object = doc.Objects.Find(object_id);
if (null != rhino_object)
{
  InstanceObject instance_object = rhino_object as InstanceObject;
  if (null != instance_object)
  {
    // TODO: update instance reference here...
  }
}

If you are tracking instance objects by something other than an object guid, than you will have to dig through all instance references until you find the one you are looking for. For example:

RhinoObject[] objects = doc.Objects.FindByObjectType(ObjectType.InstanceReference);
if (null != objects && objects.Length > 0)
{
  foreach (var obj in objects)
  {
    var instance_object = obj as InstanceObject;
    if (null != instance_object)
    {
      // TODO: Is this my instance object? If so, update instance reference and then break...
      break;
    }
  }
}