Copy file texture from a selected object


#1

Hi everyone !

I need to copy all my png texture from a shader into another folder. For example, I have a ‘Scratched_Metal’ shader created in substance painter with many maps (Base Color, Metalness, Roughness, etc…) and I want to create a script who copy all my textures file into another folder. So I created this script :

[i]import maya.cmds as mc
import shutil
dst = “C:\Users\bussi\Documents\maya\2017\prefs\scripts\HShaders_script\Icons\Shaders\METAL”
sel = cmds.ls(sl=1, dag=True, type=‘mesh’)[0]
fileList = mc.ls(type=‘file’)
for i in cmds.listConnections(sel, c=1, type=‘shadingEngine’):
for j in cmds.listConnections(i, d=1):
for f in fileList:

        fileName = mc.getAttr(f + '.fileTextureName')
        shutil.copy(fileName, dst)[/i]

But the problem in this script is that I copy every file image in my scene, and I want only the file texture on a selected object. I mean that I want to copy all the texture image of the shader of a selected mesh. And I don’t really know how to do that… Can you help me please ? Thank you !