Please try this first:
- Create a few objects in a new scene
- Assign a few different vray materials to them
- Create a surface and select it
- type visApplyMaterial (without the - sign in front)
- A dialog pops up, showing all scene materials
- Choose one to assign it to the surface, click ok
- Look into properties / material and check for:
A: Is the material name assigned ?
B: Is the plugin box checked ?
C: Is the edit button clickable or grayed out ?
In my case, A B C all work using
visApplyMaterial. I can do the same using a script, if i put the - sign in front of
-visApplyMaterial, the dialog is suppressed, then i can simply type the material name eg. “\White Plastic”. If the material has spaces in it, i need to type this in quotes. Note the \ in front of the material name. In your last script, you´re just missing this, you might print out the results of your variables to find such errors faster and handle them.
If i run your last posted script, i do not get any of A, B, C, no material gets assigned at all. Using
visApplyMaterial is the easiest method to get all things in one go. If you do not use it, you have to control (script) the material source (ByObject, ByLayer) as well. Your script does not do that.
In general, it is required to understand what material indices are. A material index can be any positive integer, including zero.
To assign one material from the scene materials, you might use the vRay.GetSceneMaterialNamesScript method and pop up a listbox filled with the
materials array. Then assign the choosen material using visApplyMaterial. Note that the object(s) to assign to need to be selected beforehand. If not, it will not work. Just enter “visApplyMaterial” to the commandline and read what it prints to the command line.