Setting layer material via script

I’m having trouble getting the V-Ray materials to apply correctly to the layers. This is the script I’m using:
_-Layer _Material \"{layerName}\" _Legacy _Material {materialName} _EnterEnd

The material is set, but not recognized as a V-Ray material. As you can see in the first snip below, the Edit button is disabled and the selected surface is not blue. After selecting the same material through the interface, the material is recognized and behaves as expected (second snip). Any insight?

[Edited to add that the V-Ray render is fine, but I want the rendered view to show the actual color as well]