IsDocumentControlled and CommitChanges

Can someone briefly explain to me the use of the RhinoCommon member CommitChanges()? I’m specifically interested in how this function works with materials and textures. My basic problem is I want to edit a material applied to a brep object and see those changes reflected in the document. Right now I’m basically doing the following:

selection=rs.GetObject(“select surface”)




tex.FileName=rs.OpenFileName(“Choose Image”)

I can see that when I create a reference to the material/texture object and subsequently edit one of its fields, that the IsDocumentControlled property goes from being true to false; I guess this means the RhinoDoc is no longer reading changes to this object. So I call CommitChanges() on this object to tell Rhino that I’ve made changes and expect to see them reflected in the doc. However, this command seems to fail every time. Should i instead be constructing a new object of this type (e.g. Texture), editing it, and applying it back to the object in question (or making a new RhinoObject?). Or is the editing in place way ok?

What is the proper way to think about accessing/editing the lower level info of a general RhinoObject?

@stevebaer, is this something you can help with?

CommitChanges just takes the object that you have modified and pushes these changes into the document. I don’t see CommitChanges in the script that you posted so I’m assuming that there must be a little more to the script.

@stevebaer- that was my basic understanding, and i assumed it was not necessary to use CommitChanges() all the way back up the object hierarchy: i.e. if i’ve changed the material, i would call commitchanges() on the it, but would not need to call commitchanges() on the docobject referencing the material. here’s the full code:

import rhinoscriptsyntax as rs
import Rhino as rh
import scriptcontext as sc

selection=rs.GetObject("select surface")




tex.FileName=rs.OpenFileName("Choose Image")


print material.CommitChanges()

print obj.CommitChanges()


Unfortunately, there is some weird stuff happening when i use this.

  1. The material.commitchanges() always returns true, but the obj.commitchanges() always returns false. is this behavior to be expected?

  2. The script only changes the rendered texture the first time I use it on a document. subsequent uses do not change the appearance of the surface.

  3. When the script works, the rendered texture changes to the image i selected, but if i go into the object properties and look at Textures, often the “Color” field will still show the filename of the old image, not the new one. Also, if i run Unwrap on the new texture, it will revert back to the texture that was on the surface prior to running the script. I assume these are related issues.

Any insight would be greatly appreciated

What is the index of the material? If it’s -1, its the default material, which you cannot modify. You might have to create a new material and assign it to the object…