Announcement

Collapse
No announcement yet.

Vray Mesh material slots to vray shaders

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

  • Vray Mesh material slots to vray shaders

    Is there a tool that comes with v-ray or a script that someone has made which will take all the material slots that come in with a v-ray proxy and the vray mesh material, and auto attach v-ray materials with them same names ? I want to be able to click on the names in the shader list (or scan the whole list) and get a bunch of attached vray mats ready to be worked on.

    Another way (maybe better) would be to have a tool that looks at materials by the same name in the scene and auto attached them to all the slots on the selected vray material node.


  • #2
    Here is a method that connects shaders with identical names to the VRayProxyMaterial.

    Code:
    def assign_shader(self, vray_proxies, *args):
    '''
    This method connects shader with identical names to the vrayProxyMtl.
    The shaders have to be in the scene. They can be loaded as a reference but must have the same namespace as the target vraymeshmtl.
    
    Args:
    vray_proxies: list of vray proxie nodes
    '''
    
    for proxy in vray_proxies:
    
        # test if node is VRayMesh
        if cmds.nodeType is not "VRayMesh":
            continue
    
        vrproxy_material = cmds.listConnections(proxy + '.fileName2', type='VRayMeshMaterial')[0]
    
        proxy_namespace = proxy.rpartition(':')[0]
    
        cmds.setAttr(vrproxy_material + ".assignShadersByName", 1)
    
        for index in range(0, cmds.getAttr(vrproxy_material + '.shaders', s=True)):
            shader_name = cmds.getAttr(vrproxy_material + '.shaderNames[{}]'.format(index)) # short shader name
            full_shader_name = proxy_namespace + ":" + shader_name # full shader name with namespace
    
           # check if shader exists in scene
           if cmds.objExists(full_shader_name) == True:
           # and then test if it is already connected
           if not cmds.isConnected(full_shader_name + ".outColor", vrproxy_material + ".shaders" + "[" + str(index) + "]"):
               # if not, connect it
               cmds.connectAttr(full_shader_name + ".outColor", vrproxy_material + ".shaders" + "[" + str(index) + "]", f=True)
           else:
               # If the shader does not exist, let the user know which shader
               print "Shader {0} is missing!".format(full_shader_name)
    Florian von Behr
    CG Supervisor
    The Scope GmbH
    Behance

    Comment


    • #3
      Thank you, unfortunately I must be doing something wrong because I get a "// Error: Line 1.23: Invalid use of Maya object "self". // " error when I try to run the script. Do you know what could be wrong ?

      Comment


      • #4
        The snippet is from a larger script with a class. It needs to be called in a class with a list of nodes as an argument.
        Florian von Behr
        CG Supervisor
        The Scope GmbH
        Behance

        Comment

        Working...
        X