RhinoCommon - Replace Material Texture File (bug?)

Hi,

I’m trying to replace the texture file of a material (see code below). The test scene is pretty simple, a cube with a material assigned on it (Material assigned by object). The assigned material has only an image file linked to its “Color Texture”.

Actually, if I use my function below on the cube, the material seems to be updated in the viewport (I use a bit further in the code “doc.Views.Redraw()”). Also, if you look at my function, I’ve add some code to check if the file has been correctly updated. The line “Rhino.RhinoApp.WriteLine(map_diffuse.FileName);” actually print the new provided file path.

However, if I go check in the “Properties Panel” of the objects (through the material tab), the texture color file path is still the old one. Same thing, if I check directly inside the material by using the “Material Panel”.

This said, if I save the model, close it, then open it, guess what? Rhino display the old one.

Is there something I’m missing?

Thanks,

bool ReplaceMaterialDiffuseMapFile(Rhino.DocObjects.Material material, string replacePath)
{
    bool result = false;
    if (material != null)
    {
        result = material.SetBitmapTexture(replacePath);
        Rhino.RhinoApp.WriteLine("Diffuse map updated: " + result.ToString());
        if (result) { 
            material.commitChanges();
            // Read the file back to verify if the change has been done correctly
            Rhino.DocObjects.Texture map_diffuse = material.GetBitmapTexture();
            if (map_diffuse != null) {
                Rhino.RhinoApp.WriteLine(map_diffuse.FileName);
            }
        }
    }
    return result;
}

No one has a cue?

Hi,
I’ve updated the first post to clarify some elements. Hope this help to understand.
Thanks

This is a know issue. @andy is looking into this and hopefully will have a fix soon.

The RenderPlugInId of the material is almost certainly not Guid.Empty. This means that another plug-in is controlling the material - probably the RDK in Rhino 5.

If you don’t mind potentially losing a rich material definition associated with this material, you can just set the RenderPlugInId property of this material to Guid.Empty when you set the texture filename. That should solve it.