Hello,
I am working with object user attributes. I am not sure why this method works as it works.
This code works as expected (found here on discourse). Attributes are updated as excepted and Attribute user panel is redrawed.
private void WriteAttributes(RhinoObject rhinoObject, List<Tuple<string, string>> attributes, ref int attributeCount)
{
ObjectAttributes objAttributes = rhinoObject.Attributes.Duplicate();
foreach (Tuple<string, string> attribute in attributes)
{
objAttributes.SetUserString(attribute.Item1, attribute.Item2);
attributeCount++;
}
RhinoActiveDoc.Objects.ModifyAttributes(rhinoObject, objAttributes, true);
}
However, following version does not work and result is deletion of all user texts.
private void WriteAttributes(RhinoObject rhinoObject, List<Tuple<string, string>> attributes, ref int attributeCount)
{
foreach (Tuple<string, string> attribute in attributes)
{
rhinoObject.Attributes.SetUserString(attribute.Item1, attribute.Item2);
attributeCount++;
}
RhinoActiveDoc.Objects.ModifyAttributes(rhinoObject, rhinoObject.Attributes, true);
}
What is the logic behind. In the first case I have all new instance of Attributes which overrides former one. In the second case I override instance of Attributes with same instance. ModifyAttributes()
is used only to instantly redraw Attribute user panel. Am I missing something (basic).
Thanks for your time and reply.
Ondřej