Assigning a lot of baked textures automatically


#1

I came across a script that someone wrote for assigning a bunch of baked AO to objects (with the same names as the baked texture files) in a scene and I tried to modify it to assign baked lighting and I’m failing so far.

Here’s the script as I have it now:

import sys
import os
import os.path
import fnmatch
import pymel.core as mel

path="C:/Dropbox (tOD)/Projects/SpatialConference/Maya/images/JPEG"
imageList=[]

# Scan Path for Images
for file in os.listdir(path):
if fnmatch.fnmatch(file,'*.jpg'):
	imageList.append(file)

# For each Image in Path Run Code
for each in imageList:
objectName=each.strip(".jpg") # Remove .PNG from File Name
#   objectName=each.strip("bakedAO-surfaceShader5SG-") # Remove Other Stuff from File Name
shader=mel.shadingNode("lambert",asShader=True,name=(objectName+"Shader"))
fileNode=mel.shadingNode("file",asTexture=True,name=(objectName+"File"))
mel.setAttr(fileNode+".fileTextureName",(path+"/"+each),type="string")
mel.connectAttr((fileNode+".outColor"),(shader+".color"),force=True)
mel.connectAttr((fileNode+".outColor"),(shader+".incandescence"),force=True)
mel.select(objectName,r=True)
mel.hyperShade(a=shader)
mel.select(clear=True) # Clear Selection

When I run this, I get the following error:

# Error: MayaNodeError: file C:\Program Files\Autodesk\Maya2020\Python\lib\site-packages\pymel\core\general.py line 170: Maya Node does not exist (or is not unique):: u'ceilin' #

Help!