SystemException, Adding Layers to Model with OpenNURBS (.NET)

Hello,
I seem to be running into a bit of snag with adding layers to a model. I am using the .NET library provided on NuGet

Problem: Whenever I try to add a layer to a model, my model’s Layer Table shows a SystemException that "index was outside the bounds of the array"

This is the code I am using…

    File3dm m_model = new File3dm();

    Rhino.DocObjects.Layer m_defaultlayer = new Rhino.DocObjects.Layer();
    m_defaultlayer.Name = "Default";
    m_defaultlayer.LayerIndex = 0;
    m_defaultlayer.IsVisible = true;
    m_defaultlayer.IsLocked = false;
    m_defaultlayer.Color = System.Drawing.Color.FromArgb(0, 0, 0);

    m_model.Layers.Add(m_defaultlayer);

I’ve tried different values for “LayerIndex” as well as not specifying one… the results are the same. Any help would be greatly appreciated.

Best,
-Nate

Have you tried running Polish() method on the file object before after adding the layer?

From your code block, I don’t understand what is going on here. But I’ve attached a simple example that works here. Does it help you any?

Program.zip (854 Bytes)

Hey Menno,
The Polish() method worked when done right after adding the layer like so…

m_model.Layers.Add(m_defaultlayer);
m_model.Polish();

Thanks!
-Nate