I keep getting errors about global name ‘surShaderOut’ is not defined, otherwise it will be the 'texP
I append the info of the texPath I have obtained into a Dict but it does not seems to be working.
For the assignTex function, it is appending the converted file - texPath onto a attribute of a custom shader
Can someone kindly advise me?
def sur_shader_ls():
surShader = cmds.ls(type = 'surfaceShader')
texDict = {}
surDict = {}
for con in surShader:
surShaderOut = cmds.listConnections('%s.outColor' % con)
surShaderTex = cmds.getAttr("%s.fileTextureName" % surShaderOut[0])
surDict.append(surShaderOut)
""" getting the directory of where the texture file is """
path = os.path.dirname(surShaderTex)
""" Only grabbing the file name """
f = surShaderTex.split("/")[-1]
""" changing the file formats """
tifName = os.path.splitexIt(f)[0] + ".tif"
texName = os.path.splitext(f)[0] + ".tex"
""" joining the file path with the new file format """
tifPath = os.path.join(path, tifName)
texPath = os.path.join(path, texName)
""" Converts all the image files to .tif then .tex and place it in the directory they are source from """
convert_text(surShaderTex, tifPath, texPath)
texDict.append(texPath)
return texPath
return surShaderOut
def assignTex():
""" Grabs the geo that the surfaceShader is assigned to """
#meshAssign = pm.listConnections(surShaderOut[1], type = "mesh")[0].longName()
meshAssign = pm.listConnections(surShaderOut[1], type = "mesh")
for geo in meshAssign:
geoName = geo.longName()
""" Creates new Generic Shader and assign it inidivually to the list of converted textures present """
newTmp = cmds.duplicate("dnGenericV5_srf", ic = True)
mm.eval("setAttr -type \"string\" " + newTmp[0] + ".Input_Texture[0].inputTextures" "\"" + texPath + "\";")
cmds.shdAssign(geoName, a = newTmp[0])