if (myInstanceObject.InstanceDefinition.UserDictionary.SetKey("mykey", 42)) {
// tried both with, and without myInstanceObject.CommitChanges(); here.
}
This succeeds. I get true back, and if I try to read the value immediately after, it’s correct (42).
In a DisplayConduit I read the value back with:
if (myInstanceObject.InstanceDefinition.UserDictionary.TryGetInteger("mykey", out int itemId)) {
// Draw textdot here with `itemId`
}
This fails. There is nothing there.
Am I at all allowed to set UserDict on InstanceDefinitions? If so, how do I “commit” the changes, so they are available everywhere?
I spent some time creating a minimal repro case from the Rhino Eto Samples.
However it works fine in the sample I have created, and I literally just copied code around
I did narrow down the issue to something really weird in our project though: The key is put into a centralized constants file as public const string. This works in the sample project. But in the full project it doesn’t work.
The video shows Visual Studio, compilation to Rhino, and demonstration of working and none-working code:
00:14 For all blocks, all blockdefs keys are displayed in a display conduit in a TextDot.
00:18 In a Panel (Stykka → Templates) there is a button that triggers the code.
00:21-00:27 When clicking the “Set for current button” button the TextDot text does not update.
00:34 Code is displayed that uses the constant string.
// This fails!
reloadedInstanceObject.InstanceDefinition.UserDictionary.Set(Constants.USER_KEY_ITEM_TEMPLATE_ID, item.id);
00:36 Code is changed to using the same string, but typed in place.
// This works!
reloadedInstanceObject.InstanceDefinition.UserDictionary.Set("com.stykka.part.item_template.id", item.id);
00:43 Compile and run.
01:33 Same button as before now works.
01:52 Constant is shown.
I’m not a C# expert. Am I declaring the constants wrong? It works in the smaller sample project.
namespace Stykka.Common.Utils
{
public static class Constants
{
public const string USER_KEY_ITEM_TEMPLATE_ID = "com.stykka.item_template.id";
}
}
I don’t really know what to do from here, other than hardcoding the strings
The video isn’t helpful. And without code I can run here, I can only speculate.
But if your conduit is holding onto an instance of InstanceDefinition and somewhere in your plug-in you add user text to it, then your conduit is going to need to re-get the instance definition as it is now holding onto an old version.
To be clear: This works’ish. There is sometimes some issues with the TextDot not displaying immediately. You either have to click the “Set” button a few times, or move the Blocks around a bit.
I think I’ve been careful to always use the Guids and always call into Rhino to get a reference to the instancedef’s, but maybe you can spot my mistake.