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.