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;
}