Access Shadernames in Vray Proxy

Hi,
is there some way to access the shader names stored in a Vray Proxy with Python or MEL?
I would like to connect shaders based on name to a VRayMeshMtl.

And what does the attribute “Assign shaders by name” in the VRayMeshMtl do? It is not explained in the documentation.

Thanks, Florian

For the moment, you can use the ply2vrmesh command-line tool with the -info option to extract the information.

The option to assign by name is helpful if the .vrmesh/Alembic file is updated on disk with a new revision that sometimes has the objects reordered.

Best regards,
Vlado

Thanks.
I’ll try to script that.

I guess access to the shader names in a vray proxy is a feature request then :wink:

Cheers, Florian

It’s already exists!

When you import VRayProxy it creates with connected VRayMeshMaterial. And you can read all info from it.

Like this.


vrProxyDAG = 'mesh' # your vrayProxy node name (transform node)
vrProxyShape = cmds.listRelatives(vrProxyDAG, s=True)[0]
vrProxyMesh = cmds.listConnections(vrProxyShape + '.inMesh')[0]
vrProxyMaterial = cmds.listConnections(vrProxyMesh + '.fileName2', type='VRayMeshMaterial')[0]

for index in range(0, cmds.getAttr(vrProxyMaterial + '.shaders', s=True)):
   print cmds.getAttr(vrProxyMaterial + '.shaderNames[{}]'.format(index)) # shader name
   print cmds.getAttr(vrProxyMaterial + '.shaders[{}]'.format(index)) # shader value, here you can connect your shader.

Cool! Thanks.
Almost finished my code where I launch ply2vrmesh.exe and parse the output. but this is much more simple. Guess I still learned alot :wink:

Hi guys,

I am trying to write something that will allow me to automatically connect shaders that already exist in the scene with the same names as those in the shader list of the proxy. The above is very useful, thanks for sharing.

I am however a novice when it comes to scripting so was hoping that someone would be able to lend a hand and offer any pointers on how best to achieve what I want to do?

Thanks in advance,

Hi,
here is a basic script that connects shaders with identical names to the VrayMeshMaterial. It works on either a selection or all VrayMeshMaterials in the scene.


import maya.cmds as cmds

def assign_shader():
    '''
    This method connects shaders with the same name to a VRayMeshMaterial.
    If something is selected, it works on the selection, otherwise it works on the whole scene.
    Author: Florian von Behr f.vonbehr at thescope.studio

    Installation:
    Copy the script to your Maya script directory.

    Load it in Maya with this command from the script editor:
    import vrayProxyTools.py
    vrayProxyTools.assign_shader()
    '''
    vray_proxys = cmds.ls(sl=True)  # vrayProxy node name (transform node)

    # if nothing is selected
    if not vray_proxys:
        # get all VRayMeshMaterial in the scene
        vray_mesh_materials = cmds.ls(type="VRayMeshMaterial")
        print vray_mesh_materials

    # if something is selected, get the VRayMeshMaterials from the selection
    else:
        vray_mesh_materials = []
        for proxy in vray_proxys:
            vray_proxy_shape = cmds.listRelatives(proxy, s=True)[0]  # get the shape node
            vray_proxy_mesh = cmds.listConnections(vray_proxy_shape + '.inMesh')[0]  # get the proxy node
            vray_mesh_materials = cmds.listConnections(vray_proxy_mesh + '.fileName2', type='VRayMeshMaterial')  # get the shader
            vray_mesh_materials.append(vray_mesh_materials[0])  # add shader to list
        print vray_mesh_materials

    # if the list of shaders is emtpty
    if not vray_mesh_materials:
        print("There are no VRayMeshMaterials in the scene.")
    else:
        for material in vray_mesh_materials:
            cmds.setAttr(material + ".assignShadersByName", 1)

            for index in range(0, cmds.getAttr(material + '.shaders', s=True)):
                 # get the shader name
                shaderName = cmds.getAttr(material + '.shaderNames[{}]'.format(index))

                # check if a shader with that name exists in scene
                if cmds.objExists(shaderName) is True:
                    # and then test if it is already connected
                    if not cmds.isConnected(shaderName + ".outColor", material + ".shaders" + "[" + str(index) + "]"):
                        # if not, connect it
                        cmds.connectAttr(shaderName + ".outColor", material + ".shaders" + "[" + str(index) + "]", f=True)
                else:
                    # If a shader with the name does not exist, let the user know which shader
                    print "Shader {0} is missing!".format(shaderName)

vrayProxyTools.zip (1.01 KB)

And if you want to learn scripting, I can really recommend this tutorial: https://www.udemy.com/python-for-maya/

Hi Florian,

Thats very helpful and kind of you. Thank you for the script and for the link to the scripting tutorial, I will surely check that out.

Thanks again.