This post is a bit more technical, and I’ll be scattering a few more in amongst my travel blog. I tend to try and automate my work life as much as possible, and this is a glimpse of what that is like. Hopefully this will help others since I couldn’t find a solution for this problem myself.
I’ve been playing around with Chaos Software’s Vray in Autodesk Maya lately and I really like it. We used it on Tron:Legacy at Digital Domain and it was amazing. I wanted to be an architect when I was younger and used 3D Studio Max in the late 90’s. I did a lot of cad work with Autocad and Intergraph, but 3D Studio Max was the first software I lit with. Boy did it blow my mind. I had designed a chair in a product design class out of a single sheet of 4’x8′ plywood, but I wanted to see it before I built it. Enter the world of lighting and texturing…
Fast forward many years…
I prefer Maya for many reasons, but mostly it’s because I learned it while working at Industrial Light and Magic on Lawrence Kasdan’s Dreamcatcher. We created a sprite system for the snow with some Mel scripting, a 3d snowflake, and compositing plugin that would read a particle file.
I’ve been finding myself doing pre-visualization for some film and commercial projects I’m developing. I want to be able to purchase models that already have shaders and textures so I could get on to the fun stuff! ACTION! It’s amazing to me how many archvis models are available for Vray for 3DS Max, but practically none for Vray for Maya.
So, with a little bit of googling, a little bit of trial and error, plenty of caffeine, and a little kitten trying to eat my rats nest of computer cables, I present my solution:
##############################################################
# Author: Zachary Cole
# Website: http://www.nzaneproductions.com
##############################################################
#
# Copyright: Creative Commons
# Attribution-ShareAlike 3.0 Unported License
#
# This work is licensed under the
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
# To view a copy of this license,
# visit http://creativecommons.org/licenses/by-sa/3.0/
# or send a letter to
# Creative Commons
# 444 Castro Street, Suite 900,
# Mountain View, California, 94041, USA.
#
# what does the above copyright mean?
# give me credit, and share any modifications you make! thanks!
#
##############################################################
#
# what does this code snippet do?
#
# it relinks materials imported from a .vrscene to
# geometry imported from a .fbx file when you wish
# to use a scene created for vray for 3dsmax in
# a scene in vray for maya
#
##############################################################
# caveats? please save backup copies of your work.
# I'm not responsible if it finds the
# higgs boson or anything unexpected.
# the steps below assume you know how to do basic
# actions in both 3ds max and maya
# support? are you paying for this? no.
# if you want to pay for it,
# then I'll try and support it.
# testing? minimal testing in 3dsmax 2012 w/ vray 2
# and maya 2011 w/ vray 1.5
# feedback? post comments on my blog!! :-)
#
# assumptions? I'm assuming that the named order is the
# same in both formats.
# i.e. the first brdf corresponds
# to the first phong. (seems to work)
##############################################################
# IMPORTANT steps:
# in 3ds max:
# select all the geometry you want to transfer
# save selected as new scene
# open scene you just saved
# export fbx
# export .vrscene
# in maya:
# change renderer to vray
# import fbx
# import .vrscene
# fix texture paths in hypershade
# run this script in the python window of the script editor
#
# wow i think these header comments are longer than my code. geeze.
##############################################################
import maya.cmds as cmds
def relinkVrayMaterials():
# get em while they're hot
mats = cmds.ls(materials=True)
phongs = []
materials = []
submaterials = []
print "#### searching through materials..."
# cycle through all materials
for mat in mats:
# look for shaders that match the naming
# when you bring them in from .fbx
if cmds.nodeType(mat) == "phong":
phongs.append(mat)
# look for shaders that match the naming
# when you bring them in from .vrscene
elif mat.find("brdf") == 0 or mat.find("material") == 0:
if mat not in submaterials:
materials.append(mat)
# layered shaders are special cases
# the connected shaders will not match up to the
# phong shaders from the fbx
if cmds.nodeType(mat) == "layeredShader":
# get the connected attrs
arr = cmds.listAttr(mat + ".inputs", m=True)
for a in arr:
# we only care about the color inputs
if a[-6:] == ".color":
# get the connected nodes
conn = cmds.listConnections(mat + "." + a)
# add them to the ignored submaterials list
for c in conn:
submaterials.append(c)
print "#### replacing material assigments..."
# cycle through all phong materials
for i in range(0, len(phongs)):
pho = phongs[i]
mat = materials[i]
# these vray materials don't have shader groups when
# they are imported from .vrscenes, so let's make one for each
matSG = cmds.sets( renderable=True,
noSurfaceShader=True,
empty=True,
name=mat+'SG' );
cmds.connectAttr( mat+".outColor",
mat+"SG.surfaceShader",
force=True)
# get the objects assigned to the phong
objs = cmds.hyperShade(objects=pho)
# assign new material to selected objects
cmds.hyperShade(assign=mat)
print "#### assigned %s to %s assigned objects" % (mat, pho)
print "#### done"
relinkVrayMaterials()

relinkVrayMaterials by Zachary Cole is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Permissions beyond the scope of this license may be available at http://www.nzaneproductions.com/contact/.

i drinked plenty of caffeine and found a litter kitten and forced him to eat my rats nest of computer cables i just forgot a little bit googling is the first step!
i was trying to find a way to replace phongs which start with1 by brdfs which start with 0 the only problem is i don’t know mel script at all!
thank you for code i really need it i want to import a chunk of materials inside many fulders and subfulders into 3ds max at once to export them for maya could you please tell the solution?
Thanks! Really useful script, right now I have the opposite problem, from maya to 3dsmax.
Thank you very much.
You’ve solved a huge problem.
Once again thanks for your effort.
Wow! pretty useful! Thanks a lot!
can you new version of this maya 2012 and max 2012 vray 2.0 last version and may be
you can edit some code
This code should work in the latest versions of maya/max/vray. Try it out and let me know!
Nice work, mate. However I am having problems when transferring mapped shaders from max to maya using your methods. Also in max I have shellac blended materials, vray light materials, vray dirt materials, and vray blend materials that all don’t seem to work or keep their maps either when converted to maya. Any help on this matter would be greatly appreciated.
Cheers
This piece of code has saved my sanity. It should be stored in the Federal Reserve Building in Washington DC and then all the cash in there given to the Author of this script. Yikes!!!
Hey Zachary
Thanks so much for this great script!
Some tips I’ve learned:
Apply edit poly modifier to the selection before exporting from Max (fixes some mesh errors)
Maya doesn’t see materials exported from Max 2013, use 2011 instead
Script works flawlessly in Maya 2013
For some reason I need to reassign textures in the Hypershade, even if they are connected and in the Source Images folder.
Some textures need to be batch processed through something like Photoshop to work properly. Don’t know why, but I couldn’t get them to work otherwise.
Thanks again for the script!
Hi,
I got the method working, well almost.
For those who can’t see the materials when importing in Maya make sure that you exported correctly. You need to set the absolute path straight to VrayRT(worked for me) and then the nodes does export correctly and you can import them in maya. You do not have to have the same location for vray for both maya and 3ds. This is just for the export so it can create a proper file.
I am however stuck at “// Error: Line 120.35: Invalid use of Maya object “material”.”
Line 120 is: mat+”SG.surfaceShader”,
And I also needed to correct all True > true.
I’m using Vray 2.0
I am trying to convert from max2012 to maya 2012…
When I try to import .vrscene I get unrecognized file format…any reason for that?
Never imported .vrscene before and not sure where I am to import from and am assuming it is just the normal import path.
Thanks so much.
Andrew
Andrew:
To import the .vrscene in Maya you must navigate to this menu item Create->Vray-> Import V-ray Material from file.
check out this maya zest tutorial for this part.:
http://mayazest.blogspot.com/2011/11/how-to-convert-autodesk-max-v-ray-to.html
Blackshore: if you want to send me a scene I could take a look.
Dan and Rich: I’ve found that some materials just don’t transfer and I ended up recreating them by hand. but this can tackle 90% of them. I also found that some of the face assigned shaders need to be reassigned by hand.
Hi Zachary,
Very useful tip and script, thanks.
i was wondering why do you reassign objects to the new created SG instead of “just ” connect vray.outcolor to the phong.surfaceShader? as the phong SG allready has all objects and faces assignement….
may be i’ve missed something, but select and reassign is longer than make one connection.
I did it modifying your script and it worked perfectly (well, for now) ๐
here’s the code to replace :
print "#### replacing material assigments..."# cycle through all phong materials
for i in range(0, len(phongs)):
pho = phongs[i]
mat = materials[i]
# get the ShadingGroup assigned to the phong
phoSG = cmds.listConnections(pho, type='shadingEngine')
# connect vray mat to phong ShadingGroup
cmds.connectAttr( mat+".outColor",
phoSG[0]+".surfaceShader",
force=True)
print "#### assigned %s to %s assigned objects" % (mat, pho)
hum; well, i just admit that there is only one SG connected : phoSG[0] ๐
thank you for your reply and if you make a try
Benoรฎt.
Hi
Your code looked very promising, but doesn’t work for me. I’m using Maya 2013 and (copy-)pasting it in the script editor and executing. That is all. Gives me this error:
# Error: IndexError: file line 112: list index out of range
Is there any way u can resolve this for me? I need this to work, since my workflow involves too much max>maya>max and am stuck on this. Pl help!
Hi,
Useless script! just doesn’t work. Asked for help, but seems u trashed my comment – was under moderation yesterday. U only want comments that praise u or ur work.
Well that is fine with me. Will start looking for alternatives now.
Keep in mind that max and maya’s default UV sets aren’t the same, so if you do some mesh operations (combine etc…) you might end up with 2 UV sets (map1 is maya’s default, UVChannel_1 max’s)
Your script works fine with max2012 > maya2014
Hi Zachary,
This looks like a great script and exactly what I need but i’m currently getting this error:
# Error: IndexError: file line 112: list index out of range #
If you could offer any assistance you would seriously be a lifesaver ๐
Thanks in advance
Oliver