C# Standalone application using Rhino3dmIO to read plugin data

Hello, I got some trouble in retrieving plugin data from the 3dm file using the Rhino3dmIO.

We made the plugin that saves both the object user data and the document user data to the 3dm file. In our workflow, we use the rhino to do the design with the plugin, but need to visualize the outcome using the web. So we are working on a simple standalone application for this purpose.

In Rhino, I managed to read/write the ArchivableDictionary data using BinaryArchiveReader.ReadDictionary() and RhinoObject.Attributes.UserDictionary, but with Rhino3dmIO library, none of these methods seems to return any results. The retrieved objects using Rhino3dmIO have the “null” UserDictionary.

Here is the partial code of the project, it would be much appreciated if anyone can offer suggestions on this. Thanks in advance.

    public static void UpdateParamsToSM(List<File3dmObject> rhinoObjs)
    {
        foreach (File3dmObject obj in rhinoObjs)
        {
            try
            {
                ObjectClass objectClass;
                if (obj.Attributes.UserDictionary.TryGetEnumValue<ObjectClass>("SM_ObjectClass", out objectClass))
                {
                    SMHeadlessInterface.gWriteRead.ReadObjects(objectClass, obj);
                }                       
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

    }

    public static void ReadScenarioFromDoc(string filePath)
    {
        SMHeadlessInterface.gScenarios.Clear();
        using (var file = new BinaryArchiveFile(filePath, BinaryArchiveMode.Read))
        {
            if (file.Open())
            {
                BinaryArchiveReader reader = file.Reader;
                ArchivableDictionary dict = reader.ReadDictionary();
                int nb = 0;
                if (dict.TryGetInteger("SM_Nb_Scenarios", out nb))
                {
                    for (int i = 1; i <= nb; i++)
                    {
                        try
                        {
                            Scenario scenario = ReadScenario((ArchivableDictionary)dict["SM_Scenario" + i]);
                            SMHeadlessInterface.gScenarios.Add(scenario.Id, scenario);
                        }
                        catch
                        {
                            Console.WriteLine("failed to load" + "SM_Scenario " + i.ToString());
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Not able to open the 3dm file.");
            }
        }
    }

The temporary solution is to serialize the document & objects user-data into a separate dataset. The console app uses the Rhino3dmIO to read geometry with Guid, then associate it to the plugin data being loaded from that separate dataset. It’s a bit inefficient to read all data from two files, but it is the only solution for now.

Hi @samytsong,

Currently, Rhino3dmIO doesn’t have a way for you to read any custom data other than user strings. It’s something we hope to support in the Rhino 7 timeframe.

– Dale

Hi Dale, thanks for confirming this, hope there is such a function in the near future.

Hello,

Has there been progress on this subject ? I’m especially interested in the support of UserDictionary in rhino3dm python library. For now I just use UserStrings and analyse the text but usual types would be great :slight_smile:
Also is there a way to display those dictionaries inside the Rhino 7 client ? I could only see the User Strings in the User Data tab and only for 3D objects (not for layers for example).

Thanks

UserDictionary is currently only supported in our .NET version. We need to rewrite the dictionary in C++ to make it available in other languages which is a pretty big job

Thanks for the answer, can you tell is this is in the current backlog or is it not for a foreseeable future ?

I won’t be able to get to this in the next month.

Hi @thomas.pitiot,

If you write document user data, by overriding your plug-in’s ReadDocument method, then you can read this data in a standalone C# application using Rhino3dm using File3dmPlugInDataTable.TryRead.

Also, if you add custom user data to an Rhino object, by implementing a custom UserData inherited class, then you can read this data in a standalone C# application using Rhino3dm using File3dmObject.TryReadUserData.

Hope this helps.

– Dale

3 Likes