Hi all - Im attempting to create History for a brep solely for the purpose of getting a warning when editing the brep, because in a later Command the original object is being referenced by other objects as a child via GUID in User Text.
I have attempted to create a HistoryRecord and add the HistoryRecord instance to a duplicate of the original Brep with the aim of the deleting the original object and ending up with an identical Brep, but with History enabled. Here’s the method:
public static List<Guid> CollectBrepsWithHistory(GetObject go, RhinoDoc doc, Command commandInstance)
{
var newBrepGuids = new List<Guid>();
for (int i = 0; i < go.ObjectCount; i++)
{
Rhino.DocObjects.ObjRef objRef = go.Object(i);
Brep brep = objRef.Brep();
if (brep == null)
{
RhinoApp.WriteLine("Object is not a valid Brep. Skipping.");
continue;
}
Guid originalId = objRef.ObjectId;
Brep dupBrep = brep.DuplicateBrep();
if (dupBrep == null)
{
RhinoApp.WriteLine("Failed to duplicate Brep. Skipping.");
continue;
}
HistoryRecord history = new HistoryRecord(commandInstance, 0);
history.SetBrep(0, brep);
history.SetString(0, originalId.ToString());
ObjectAttributes attr = new ObjectAttributes();
Guid newId = doc.Objects.AddBrep(dupBrep, attr, history, false, false);
if (newId != Guid.Empty)
{
newBrepGuids.Add(newId);
}
else
{
RhinoApp.WriteLine("Failed to add duplicate Brep with history to the document.");
}
}
doc.Views.Redraw();
return newBrepGuids;
}
Unfortunately, I cannot get the History to actually be enabled, I’ve suspected it might be because Im performing actions later on that break history in the command itself, but even when looking at the C# History Developer Sample, I could not get History to be activated, not even when writing a snippet creating a Loft and adding history to a new object.
Can anybody help me out here?