Editable CRhinoHistoryRecord Example (C/C++ API)?

I need an example of creating a CRhinoCommand with editable history, i.e., something like _BlendCrv. @dale has this request logged as RH-75629.

In the meantime, does anyone else have a relevant example they could share?

Here you go:

cmdSampleBlendCurve.cpp

– Dale

Thanks, Dale. There are two things I need clarification on:

  1. During the edit function, I see how you’re custom go.GetObjects(1, 1) tests curves for valid input. Does that test everything selectable to highlight valid inputs?
class CGetSampleBlendCurve : public CRhinoGetObject
....
bool CGetSampleBlendCurve::CustomGeometryFilter(const CRhinoObject* object, const ON_Geometry*, ON_COMPONENT_INDEX) const
{
  return theSampleBlendCurveCommand.HasSampleBlendSurfaceHistory(object);
}

example of a red blend crv being highlighted yellow during an edit routine:

image

I thought you’d have to interact directly with CRhinoHistoryRecordTable, looping through all the records to find those created by your derived CRhinoCommand, then feeding those to a display conduit.

  1. Is CreateObjectHistory() a create-or-overwrite statement? Is the overwrite based solely on the object’s GUID, meaning one command can overwrite a history record created by another command? And can this (create/update) be called sometime later, well after the child is added to the objects table?
        context.m_doc.m_history_record_table.CreateObjectHistory(curve_obj, history);
        context.m_doc.ReplaceObject(object, curve_obj);

I have a use case where I need to copy the history from curveA, edit the values, and apply it to curveB, which was originally created by a different command. If you’re curious why I’d need that, I can share my screen and walk you through it.

Hi @EricM,

It only tested what you’ve picked on while CGetSampleBlendCurve::GetObjects is running.

CRhinoHistoryRecordTable::CreateObjectHistory will add a new history record to the input object if doesn’t have one already. If it already has a history record, the function will replace the exising record with a new one.

Although that is not the intent, I don’t see anything that would prevent one from doing this.

– Dale

Okay, that was my understanding. So, what is the right way to get all the objects created by a specific implementation of a CRhinoCommand?

You’ll need to iterate the document, something like this perhaps:

int GetRhinoCommandHistoryObjects(
  CRhinoDoc& doc, 
  ON_UUID command_id, 
  ON_SimpleArray<const CRhinoObject*>& history_objects
)
{
  CRhinoObjectIterator it(doc, CRhinoObjectIterator::normal_objects, CRhinoObjectIterator::active_objects);
  const CRhinoObject* object = nullptr;
  for (object = it.First(); nullptr != object; object = it.Next())
  {
    {
      const CRhinoHistoryRecord* history_record = object->HistoryRecord();
      if (nullptr != history_record)
      {
        if (0 == ON_UuidCompare(command_id, history_record->m_hr.m_command_id))
          history_objects.Append(object);
      }
    }
  }
  return history_objects.Count();
}

– Dale