Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Material Utility
- # Save Materials
- from pymel.core import *
- def saveMat(s):
- try:
- objSG = s.getShape().listConnections(s, t = "shadingEngine")
- except:
- print "cant save mat for ", s
- pass
- return objSG
- def readMat(*args):
- global saveFile, w
- filePath = fileDialog2(dir = w, ds=1, fm = 1 )[0].replace("\\","/")
- readFile = open(filePath,"r").readlines()
- formated = []
- for item in readFile:
- item = item.split(":")
- formated.append(item)
- for obj in formated:
- try:
- sets(obj[1], forceElement = obj[0] )
- except:
- print "cant assign mat",obj[1], "And objects obj", obj[0]
- print "done assigning materials"
- def writeMat(*args):
- global saveFile, w
- w = workspace(act=1, q=1)
- filePath = fileDialog2(dir = w, ds=1, fm = 3 )[0].replace("\\","/")
- saveFile = open(filePath+"/materialSaver.txt", "w+")
- sl = selected()
- for s in sl:
- objMat = saveMat(s)
- try:
- writer = s + ":" + objMat[0] + "\r\n"
- saveFile.write(writer)
- except:
- pass
- saveFile.close()
- print "done getting materials"
- sl = selected()
- # Gui
- win = window(title= "Material Utility", s=0)
- mainLayout = rowColumnLayout(nc=1)
- #saveLocation = button(l="Save file Location", command=Callback(getLocation))
- saveMaterialsBtn = button(l="Save Materials", command=Callback(writeMat))
- getMaterialsBtn = button(l="Get Materials", command=Callback(readMat))
- win.show()
Advertisement
Add Comment
Please, Sign In to add comment