Hi there,
I am trying to determine the command for connecting shaders to a vraymeshmtl node automatically, by name.
I know how to do it via shader value but not name.
For example, I would like to connect the following shader to the same shader name in the vray proxy, rather than use the shader value. Even more specifically, I would like to do this ‘en mass’ for all the shader names in the proxy.
connectAttr -f e_plasticBlackSmooth_SHD.outColor Ascent_vraymeshmtl.shaders[0];
Any help appreciated
Thanks
I’ve done something like this in the past:
import pymel.core as pm
for vrayMeshMat in pm.ls(type='VRayMeshMaterial'):
vrayMeshMatShdList = [x for x in enumerate(vrayMeshMat.shaderNames.get())]
for i, shdName in vrayMeshMatShdList:
if not vrayMeshMat.shaders[i].isConnected():
pm.PyNode(shdName).outColor >> vrayMeshMat.shaders[i]
It’s quick and dirty and doesn’t take into account if the shader indices are jumbled, but should work for most cases.
This is probably better:
import pymel.core as pm
for vrayMeshMat in pm.ls(type='VRayMeshMaterial'):
vrayMeshMatShdList = zip(vrayMeshMat.shaders.getArrayIndices(), vrayMeshMat.shaderNames.get())
for i, shdName in vrayMeshMatShdList:
if not vrayMeshMat.shaders[i].isConnected():
shd = pm.ls(shdName)
if shd:
shd[0].outColor >> vrayMeshMat.shaders[i]
else:
pm.warning('Failed to find shader: '+shdName+'. Skipping')
I didn’t have a chance to test it, but it should take care of any index issues and also not fail if it can’t find a shader with a matching name in the scene..