Sorry for reviving this thread, but I wanted to let those interested know that there is a work around to this: define an Interface.
Define the interface in your common library, and implement it in your plugin. You then can iterate through the UserDataList
on an object looking for UserData
that implements your interface.
@stevebaer or @dale do you see any pitfalls with using this approach?
Thanks
For Example:
In Common Library
public interface ICustomUserData
{
public string Notes {get; set;}
public string Description {get;}
}
In Rhino Plugin
//This GUID is empty, use your own!
[Guid("00000000-0000-0000-0000-000000000000")]
public class CustomUserDataImpl : UserData, ICustomUserData
{
/// Standard Implementation from SampleCSUserData Project ///
}
In Grasshopper Plugin
protected override void SolveInstance(IGH_DataAccess DA)
{
var objGuid = Guid.Empty;
if (!DA.GetData(0, ref objGuid)) return;
var ro = RhinoDoc.ActiveDoc.Objects.Find(objGuid);
if (ro == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The Id is not for a Rhino Object");
return;
}
foreach (var ud in ro.Attributes.UserData)
{
if (ud is ICustomUserData csd)
{
DA.SetData(0, csd.Notes);
return;
}
}
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Object Did not contain Custom User Data");
return;
}