How Do You Retrieve a Transform from an ArchivableDictionary

Hey guys,

I am using the Rhino3dm NuGet library and trying to calculate and store a Transform object into UserDictionary of a layer so that I can retrieve it later. The ArchivableDictionary class which has a Set(string key, Transform xform) which looks to be exactly what I want but I don’t see a corresponding way to get that value back as a Transform object.

string key = "MagicScaleKey";
Transform tScale = Transform.Scale(Point3d.Origin, myScaleFactor);

myFile3dm.AllLayers.First().UserDictionary.Set(key, tScale);

Any suggestions?

Hi @Mike25, you can use ArchivableDictionary.TryGetValue to receive it.

_
c.

Thank you for this suggestion.

It seems that I may actually have a bigger problem. With the code above, the UserDictionary property on my layers are all returning NULL.

I found this thread: C# Standalone application using Rhino3dmIO to read plugin data - #6 by stevebaer

This seems to indicate that UserDictionary, or rather the ArchivableDictionary class, is unavailable in Rhino3dm.

My question now is, in what way can I both read and write Transform objects to be stored inside a file using Rhino3dm?

Hi @Mike25,

Are you not using the .NET version? That is, are you using Rhino3dm.py or Rhino3dm.js?

Thanks,

– Dale

I am writing a .NET 6.0 C# library which uses the Rhino3dm NuGet package so that would be using the .NET version, yes?

I saw the note from Steve B in the thread I linked above which implied that the UserDictionary should be supported in .NET but I’m guessing since I am in .NET 6.0 that the build of Rhino3dm doesn’t have these features due to cross-platform compatibilty. Correct me if I’m wrong.

In any case what I am seeing is that in this code:

File3dm inputFile = File3dm.Read(inputFilePath);

Layer layer = inputFile.AllLayers.First();

The layer.UserDictionary property is returning NULL.

Hi @Mike25,

Yes, I see the issue. It seems like we should be able to provide access to ArchivableDictionary from Rhino3dm .NET. I’ve opened an issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-71884

In the mean time, you might need to consider using another form of meta data. Of course, user strings work in both RhinoCommon and Rhino3dm .NET. But for objects such transforms, this might not be all that elegant.

Document user data and Rhino object user data can be read with Rhino3dm .NET using File3dmPlugInDataTable.TryRead and File3dmObject.TryReadUserData, respectively. This requires that your share your user data code between your Rhino plug-in and your external application. I don’t believe we provide any example of this. But I can code up something you need help.

– Dale

Hey Dale,

Well darn, that was not the answer I was hoping for. I may have to try converting Transform objects to strings and back and using the user strings. Like you said, not elegant. Down the road I foresee wanting to write other types of data so getting access to the ArchivableDictionary will be a big help.

An example of how to use document user data and rhino object user data with Rhino3dm .NET would be very welcome.

Thanks,
Mike

Hi @Mike25,

Here is a simple project that shows how to write object user data and read it with Rhino3dm.

TestUserData.zip (30.3 KB)

And here is one for reading document user data:

TestDocData.zip (41.5 KB)

More on user data:

Rhino - Plugin User Data

There are samples on how to inherit from UserData on GitHub

GitHub - mcneel/rhino-developer-samples: Rhino and Grasshopper developer sample code

– Dale

1 Like