Maya python batch shader update& re-export

I’m an infant tech artist just getting into Python for Maya.

I have a batch of game assets to re-export with an updated shader.
Each asset has its own directory structure with
…Assets\assetName\Source\assetName.mb
…Assets\assetName\Export\assetName.mmf (adobe’s alpine format)

I want to write a python script that will

1.) loop through Assets\ and open each assetName\assetName.mb file
2.) import myNEWshader.mb (which contains only a new shader)2replace myOldShader
3.) replace myOLDshader with my myNEWshader.mb
4.) export the asset to its corresponding assetName\Export\ folder

Manually a tedious process…
I’m certain this is the kind of batch operation gets done all the time by ‘grown up’ tech artists.
I woudln’t presume to ask anyone to write this for me, but if anyone knows of a python script with similar functionality
(and hopefully nice comments) I’d love to take a look at it.

Hm,

1.) Sounds like os.walk
2. 3. 4.) Sound like straight forward pymel

For batching, read this Support and Problem Solving | Autodesk Support

thanks!

Something dirty like this should in theory work and hopefully get you started with the batching process. (not tested)
Have fun and hope this helps!


import pymel.core as pm

#Specify something like 'X:/Project/Assets/'
batchDir = 'Assets/'

#Get folders in Assets\...
folder = pm.getFileList(folder=batchDir)
for assetFolder in folder:
    #Finds *.mb file in Assets\assetName\Source\
    sourceAssets = pm.getFileList(folder=(batchDir + assetFolder + '/Source/'), filespec="*.mb")
    
    #opens *.mb in Assets\assetName\Source\
    for assets in sourceAssets:
    	#opens *.mb in Assets\assetName\Source\
    	pm.system.openFile(batchDir + assetFolder + '/Source/' + assets, f=True)

    	############
    	#Batch Start
    	
    	#1. pm.system.importFile(myNEWshader.mb)
    	
    	#2. replace myOLDshader with myNEWshader
    	
    	#Batch End
    	############

    	#Saves *.mb to Assets\assetName\Export\
    	pm.system.saveAs(batchDir + assetFolder + '/Export/' + assets)