Announcement

Collapse
No announcement yet.

What is the command for connecting shaders to vraymeshmtl by name instead of number?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the command for connecting shaders to vraymeshmtl by name instead of number?

    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.

    HTML Code:
    connectAttr -f e_plasticBlackSmooth_SHD.outColor Ascent_vraymeshmtl.shaders[0];
    Any help appreciated

    Thanks

  • #2
    I've done something like this in the past:
    Code:
    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.

    Comment


    • #3
      This is probably better:

      Code:
      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..

      Comment


      • #4
        Thanks Dan!

        Will give it a try now.

        Comment

        Working...
        X