Hey developers!
In my plugin I need to attach custom UserData to geometry and have it grouped in scenarios. Each scenario, can hold different UserData values.
I have a custom BuildingData class derived from UserData attached to Geometry which serializes properly.
buildingObject.Geometry.UserData.Add(new BuildingData(BuildingType.Residential, 10));
public BuildingData( BuildingType type, double height )
{
Type = type;
Height = height;
}
protected override bool Write( BinaryArchiveWriter archive )
{
var dictionary = new Rhino.Collections.ArchivableDictionary(1, nameof(BuildingData));
dictionary.Set(nameof(Type), Type.ToString());
dictionary.Set(nameof(Height), Height);
archive.WriteDictionary(dictionary);
return !archive.WriteErrorOccured;
}
To group the entries under scenarios, I was thinking of using a Dictionary. How can one create a UserDictionary with a custom class, though? I tried using an ArchivableDictionary like so but this doesn’t serialize properly.
var s1 = new ArchivableDictionary(new BuildingData(BuildingType.Residential, 10));
buildingObject.Geometry.UserDictionary.Set("1", s1);
Any ideas?