Hi,
It appears that there may be a bug related to the case sensitivity of userstrings. Specifically, the code should be able to differentiate between userstrings with similar names but different capitalization. However, it seems that in some cases, the code is not behaving as expected and is matching userstrings with different capitalization.
Dictionary<string, string> keyMap = new Dictionary<string, string>
{
{ "IDN2", "idn" },
{ "End1", "end1" },
{ "End2", "end2" },
{ "Group", "assieme" },
{ "Type", "type" },
{ "Mat", "mat" }
};
.....
RhinoObject obj = id.Object();
if (obj.Attributes.Name != null)
{
foreach (var oldKey in keyMap.Keys)
{
// Check if the old key exists and has a value
string value = obj.Attributes.GetUserString(oldKey);
if (!string.IsNullOrEmpty(value))
{
// Modify the value and key, and delete the old key
string newKey = keyMap[oldKey];
obj.Attributes.DeleteUserString(oldKey);
obj.Attributes.SetUserString(newKey, value);
Rhino.RhinoApp.WriteLine("🆔 ➡️ " + obj.Attributes.Name + " "+oldKey + " ConvertitoreShip1aShip2 ➡️ "+ newKey);
}
}
obj.CommitChanges();
}
In the context of my problem, there are 2 user strings “IDN” and “idn”, it mixes up IDN and idn even though the capitalization is different. I applied a sketchy hotfix so that It works for me, however It would be better if the SetUserText / DeleteUserText method correctly handled capitalization
@dale