CommitChanges returns false. How to debug?

Here is a snippet of my code going through a list of ObjRefs and trying to change object color

// selected is an array of ObjRef
foreach (int i in ri)
{
    selected[i].Object().Attributes.ColorSource = ObjectColorSource.ColorFromObject;
    selected[i].Object().Attributes.ObjectColor = colorDialog1.Color;
    if (!selected[i].Object().CommitChanges()) MessageBox.Show("didn't happen");
}

How would I debug when that CommitChanges() call returns false? BTW no exception thrown at all…

A bit more background is that the variable “selected” is an ObjRef[] assigned to a class variable of a winforms UserControl. “ri” is just a list of int. I click a button and it calls up a winforms ColorDialog. if result is ok, assign that color to all these objects.

1 Like

Hi @Will_Wang,
I had the same problem. I’m not sure what exactly is causing the issue in the background. But here is a work-around.

foreach (int i in ri)
{
    RhinoObject rObj = selected[i].Object();
    rObj.Attributes.ColorSource = ObjectColorSource.ColorFromObject;
    rObj.Attributes.ObjectColor = colorDialog1.Color;
    if (!rObj.CommitChanges()) MessageBox.Show("didn't happen");
}
1 Like

Thank you much!
I have suspected that. I hope McNeel team sees this. In any case, they could possibly build in some kind of intellisense that says I cannot make calls right off of the Object() method. No sure what the exact programming term for it is but I’ve run into this before, where VS told me I shouldn’t do the call in-line. Or maybe I was in IronPython accessing the .NET SDK. It would throw an exception.

In my case i realized that “Rhino.DocObjects” module is not imported in the code file, then i imported it and problem solved.