Hey @dale
< FYI - My code is F#, but I’m using dotPeek on the .rhp file to get the equivalent C#. If a variable name is generated, I do a quick notepad find and replace with something friendlier.>
I’m adding a HistoryIndex to UserData, but Find() always returns null (Unit) when I try to read it during the replay:
public override Unit replayChildMissing(ReplayHistoryResult r)
{
if (!(r.ExistingObject.UserData.Find(typeof (HistoryIndex)) is HistoryIndex historyIndex))
return (Unit) null;
if (historyIndex.Index >= this.updatedObjs.Length)
return (Unit) null;
ReplayHistoryResult replayHistoryResult = r;
GeometryBase updatedObj = this.updatedObjs[historyIndex.Index];
ObjectAttributes attributes = replayHistoryResult.ExistingObject.Attributes;
...
}
This UserData is to support when a users deletes one of the children, I can update the remaining ones. The standard ReplayHistory() sample code shows something like this, where if the lengths don’t match you fail without updating history:
if (updatedObjs != replay.Results.Length)
return false;
If my lengths don’t match, I switch to that replayChildMissing()
version where I have the original length and index for that child:
public class HistoryIndex : Rhino.DocObjects.Custom.UserData
{
internal int Index;
internal int Length;
I set those values when the children are added to the doc:
public override Unit addChildren(HistoryRecord hRecord, ObjectAttributes parentAttrib, int len, int idx, GeometryBase g)
{
HistoryIndex historyIndex = new HistoryIndex();
historyIndex.SetValues(idx, len);
parentAttrib.UserData.Add((Rhino.DocObjects.Custom.UserData) historyIndex);
if (g is InstanceReferenceGeometry referenceGeometry)
{
InstanceDefinition id = this.doc.InstanceDefinitions.FindId(referenceGeometry.ParentIdefId);
this.doc.Objects.AddInstanceObject(id.Index, referenceGeometry.Xform, parentAttrib, hRecord, id.IsReference);
return (Unit) null;
}
this.doc.Objects.Add(g, parentAttrib, hRecord, false);
return (Unit) null;
}
I can see the data in the debugger. Any ideas what’s going on?