Help with "description" from "Rhino.DocObjects.Custom.UserData"

Hello fellow computational designers,

I am currently writing a plug-in for rhinoceros, in which I am working with a class derived from “Rhino.DocObjects.Custom.UserData”.

I currently want to update the “public override string Description”, every time any of the data from within this User Data is changed. The thing is that I don’t know from where it is triggered from. Anyone has any idea how this override works?

Thanks in advance for any input, I really appreciate the help. If there is anything more that I can add or any questions that I can answer I am here for that! Thanks!

Hi @Frusciante,

Perhaps this?

/// <summary>
/// Some UserData-inherited class
/// </summary>
public class TestUserData : UserData
{
  private string m_description = nameof(TestUserData);

  /// <summary>
  /// Gets and sets the custom description
  /// </summary>
  public string CustomDescription
  {
    get => m_description; 
    set => m_description = string.IsNullOrEmpty(value) ? nameof(TestUserData) : value;
  }

  /// <summary>
  /// UserData.Description override
  /// </summary>
  public override string Description
  {
    get => m_description;
  }
}

– Dale

Hi Dave,

Is there a reason why the following wouldn’t work?

public override string Description => this.GetSerializedUserData();

Taking into account the following method:

public string GetSerializedUserData()
{
   StringBuilder sb = new StringBuilder(); ;


   sb.AppendLine($"{nameof(StatusContainer)}:");
   sb.AppendLine($"\t{nameof(StatusContainer.IsActive)} =  {StatusContainer.IsActive}");

   sb.AppendLine($"{nameof(LabelContainer)}:");
   sb.AppendLine($"\t{nameof(LabelContainer.Tag)} = {LabelContainer.Tag}");
   sb.AppendLine($"\t{nameof(LabelContainer.Index)} = {LabelContainer.Index}");

   return sb.ToString();
}

I´m just trying to understand…

Have you tried?

– Dale

Yes, but this doesn’t apply to a changing field. Only to retrieves the same value every time. It works in the same sense that my approach works, because it is only set once, when the class is initiated.

I see that the description override is not being called every time I open the details panel in Rhino, because I added a “RhinoApp.Writeline” to teste everytime this override is run, and it is only run once when class is initiated.

I now see the problem… It is not that the description is not updating, it is that the “details…” button is not retrieving the description again. Or so it seems like, because when I call RhinoApp.WriteLine(this.Description); it does give the correct values, but when I click on that UI menu, the values are not updated correctly. They are just set as they were when the CustomUserData was attatched to the object.

See the difference betweeen:

A) What is being printed to the rhino command line when calling for the description:

B) The text inside the “Details…” UI.

Perhaps something like this:

StringBuilder sb = new StringBuilder();
sb.Append("\n\tEvery");
sb.Append("\n\tgood");
sb.Append("\n\tboy");
sb.Append("\n\tdeserves");
sb.Append("\n\tfudge.");
        
userData = new TestFruscianteUserData { Notes = sb.ToString() };
attributes.UserData.Add(userData);

doc.Objects.ModifyAttributes(rhinoObject.Id, attributes, false);

– Dale