Renaming Objects with Rhino3dmIO

First, I’ll admit that I’m not a Rhino user. Having said that, I’ve been tasked with renaming a number of Point objects in a series of 3dm files. Using Rhino3dmIO, I have been able to open and read the files. I can get the names of the Point objects within the file. But, I can’t rename them.

Here’s what I’m doing:

At this point, filelist has already been populated with a series of FileInfo objects representing the 3dm files. OLD_Names[] contains the list of existing names, and NEW_names[] contains the list of new names.

int numObjects;
string name;
bool fileChanged;

foreach (FileInfo fi in filelist)
{
    fileChanged = false;

    File3dm rhinofile = File3dm.Read(fi.FullName);
    numObjects = rhinofile.Objects.Count();

    for (int i=0; i<numObjects; i++)
    {
        name = rhinofile.Objects.ElementAt(i).Name;
        for (int j =0;j<OLD_Names.Count(); j++)
        {
            if (name == OLD_Names[j])
            {
                fileChanged = true;
                rhinofile.Objects.ElementAt(i).Name = NEW_Names[j];
             }
         }
     }

     if (fileChanged)
     {
         rhinofile.Write(fi.FullName, rhinofile.Revision);
      }
 }

The code doesn’t crash, no errors are thrown. The new name just isn’t accepted. I know that RhinoCommon has a CommitChanges method and a ModifyObjectAttributes method. However, Rhino3dmIO seems to lacking those.

I’m using Visual Studio 2015, and I downloaded the Rhino3dmIO library from NuGet, I did not compile it from source.

Thanks for any suggestions.
Don

Hi @Don_Sayler,

Your code, in theory, should work. But an object’s attributes read from a 3dm file are basically read-only.

I’ve made a YouTrack item to fix this.

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

– Dale

Hi Dale.

Thanks for responding.

I wondered about that, but the Name property has {get; set;} even though the Attributes are read only.

I came up with a way to do it by essentially re-creating the objects with the ‘bad’ name, changing the name, and adding the newly created object to the object table. Then I delete the original. Seems to work.

Best Regards,
Don Sayler

RH-40742 is fixed in the latest Rhino 6 Service Release Candidate