Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Proxy maker
- # v1.2
- from pymel.core import *
- import os
- def getMat(s):# get material from selected
- matSG = s.getShape().listConnections(t="shadingEngine")
- mat = ls(listConnections(matSG),materials=1)
- return matSG, mat
- def assMat(s,matSG,mat):
- try:
- sets(matSG, e=1, forceElement = s)
- print "material added"
- except:
- try:
- hyperShade(s, a = mat)
- print "material assigned"
- except:
- select(s,add=1)
- print "could not assign material to:", s
- def getPath():
- w = workspace(act=1, q=1)
- filePath= fileDialog2(dir = w, ds=1, fm = 2)
- if filePath:
- filePathTxt.setText(filePath[0].replace("\\","/") )
- return filePath
- def makeProxies():
- filePath = filePathTxt.getText()
- matList = []
- StartFrame = startFrameTxt.getText()
- EndFrame = endFrameTxt.getText()
- ByFrameAmnt = ByFrameAmntTxt.getText()
- if DoNewFolderCheck.getValue() == True:
- filePath = filePath+"/"+ str(NewFolderNameText.getText())
- make_dir(filePath)
- filePathS = filePath
- childCheck = []
- sl = selected()
- select(cl=1)
- #progWin = progressWindow(isInterruptable=1, t= "Exporting...", min = 0, max = len(sl))
- i = 0
- for ss in sl:
- #filePath = filePathTxt.getText()
- #progressWindow(progWin, edit=True, pr = i)
- if DoSubFolderCheck.getValue() == True:
- filePath = filePathS+"/"+ str(ss+"_proxy_")
- make_dir(filePath)
- print "Exporting to "+ filePath
- setAttr(ss.visibility,1)
- if DoAnimCheck.getValue():
- select(ss)
- rsProxy(fp =filePath+"/"+ss+".rs",b= float(ByFrameAmnt), sl=1, s=int(StartFrame), e = int(EndFrame))
- print "Exporting Animation"
- else:
- select(ss)
- rsProxy(fp =filePath+"/"+ss+".rs", sl=1)
- select(cl=1)
- rsProxyNode = createNode("RedshiftProxyMesh",n = ss+"_"+ObjectNameText.getText()+"_proxy")
- rsProxyMesh = createNode("mesh",n = ss+"_"+ObjectNameText.getText()+"Shape")
- rsProxyNode.outMesh >> rsProxyMesh.inMesh
- setAttr(rsProxyNode.fileName, filePath+"\\"+ss+".rs")
- if UseMaterial.getValue():
- print "Use material"
- childCheck = ss.listRelatives(c=1)# see if its a group
- if len(childCheck) < 2:
- matSG, mat = getMat(ss)
- assMat(rsProxyMesh,matSG[0],mat)
- else:
- assMat(rsProxyMesh,"initialShadingGroup","initialShadingGroup")
- proxy = listConnections(rsProxyMesh, t="RedshiftProxyMesh")[0]
- if DoAnimCheck.getValue():
- setAttr(proxy + ".useFrameExtension", 1)
- pp = "####"
- setAttr(rsProxyNode.fileName, filePath+"\\"+ss+"."+pp+".rs")
- displayModeState = 0
- proxyState = DisplayModeOptions.getValue()
- if(proxyState == "Bounding Box"):
- displayModeState = 0
- if(proxyState == "Preview Mesh"):
- displayModeState = 1
- pcValue = PcText.getText()
- setAttr(proxy + ".displayPercent", int(pcValue))
- setAttr(proxy + ".displayMode", displayModeState)
- if HideOriginalCheck.getValue() == 1:
- setAttr(ss+".visibility", 0)
- ObjId = 0
- if ObjectIdOverrideCheck.getValue() == True:
- ObjId = int(ObjIdText.getText())
- setAttr(rsProxyNode +".objectIdMode", 1)
- setAttr(rsProxyMesh +".rsObjectId", ObjId)
- """
- else:
- if len(childCheck) < 2:
- ObjId = getAttr(ss+".rsObjectId")
- """
- """
- if progressWindow(progWin, query=1, isCancelled=1):
- print "killed at",ss, i+1
- break
- """
- i += 1
- progressWindow(progWin, endProgress=1)
- def AnimationExportState():
- FrameRangeLayout.setEnable(DoAnimCheck.getValue())
- def UpdateTextProxyDisplay():
- PCValue = PcTextSlider.getValue()
- PcText.setText(str(int(PCValue)))
- def DisplayModeTrack():
- proxyState = DisplayModeOptions.getValue()
- if(proxyState == "Bounding Box"):
- DisplayModePM.setEnable(0)
- if(proxyState == "Preview Mesh"):
- DisplayModePM.setEnable(1)
- def SetSlider():
- pcValue = PcText.getText()
- PcTextSlider.setValue(float(pcValue))
- def ObjIDState():
- ObjIdText.setEnable(ObjectIdOverrideCheck.getValue())
- def make_dir(path):
- """
- input a path to check if it exists, if not, it creates all the path
- :return: path string
- """
- if not os.path.exists(path):
- os.makedirs(path)
- return path
- def NewFolderName():
- FolderCheckLayout.setEnable(DoNewFolderCheck.getValue())
- # GUI
- try:
- if(window(win, exists=True)):
- deleteUI(win)
- except:
- pass
- win = window(title= "ProxyMaker", s=1)
- mainLayout = rowColumnLayout(nc=1)
- text(l="Redshift Proxy Creator",p=mainLayout)
- text(l=" ",p=mainLayout)
- # File path
- FilePathLayout = rowColumnLayout(nc=1, p=mainLayout)
- text(l="File Path",p=FilePathLayout,al="left")
- filePathTxt = textField(p=FilePathLayout,w = 200)
- w = workspace(act=1, q=1)
- filePathTxt.setText(w)
- getPathBtn = button(l="get path", command=Callback(getPath))
- # New folder
- DoNewFolderCheck = checkBox(l="MakeNewFolder",p=mainLayout, cc=Callback(NewFolderName),v=1)
- FolderCheckLayout = rowColumnLayout(nc=2, p= mainLayout, en=1)
- text(l="Folder name",p=FolderCheckLayout)
- NewFolderNameText = textField(tx="_ProxyExport_",p=FolderCheckLayout, w=100)
- DoSubFolderCheck = checkBox(l="MakeSubFolders",p=FolderCheckLayout)
- # Animation
- DoAnimCheck = checkBox(l="Export Animation",p=mainLayout, cc=Callback(AnimationExportState))
- FrameRangeLayout = rowColumnLayout(nc=3, p=mainLayout, en=0)
- text(l="Frame Range",p=FrameRangeLayout)
- startFrameGet = int(playbackOptions(min=1,q=1))
- endFrameGet = int(playbackOptions(max=1,q=1))
- startFrameTxt = textField(tx=str(startFrameGet),w=50,p=FrameRangeLayout)
- endFrameTxt = textField(tx=str(endFrameGet),w=50,p=FrameRangeLayout)
- text(l="By Frame",p=FrameRangeLayout)
- ByFrameAmntTxt = textField(tx=1,w=50,p=FrameRangeLayout)
- # Settings proxyMeshShape"
- ProxySettingsLayout = frameLayout(bgc = [.2,.3,.5], en = 1, label='Proxy Settings', cll =1, cl=1,p= mainLayout )
- ObjectNameLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
- text(l="ObjName_+",p=ObjectNameLayout)
- ObjectNameText = textField(tx="proxyMesh",p=ObjectNameLayout, w=150)
- UseMaterial = checkBox(l="Use Material", p=ProxySettingsLayout, v=1)
- HideOriginalCheck = checkBox(l="Hide original" ,p=ProxySettingsLayout,v=1)
- #object id
- ObjIDLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
- ObjectIdOverrideCheck = checkBox(l="Object ID", p=ObjIDLayout, v=0, cc=Callback(ObjIDState))
- ObjIdText = textField(tx="1",p=ObjIDLayout, w=50)
- # Display mode
- DispModeLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
- text(l = "Display Mode",p=DispModeLayout,al="left")
- DisplayModeOptions = optionMenu(p=DispModeLayout, cc=Callback(DisplayModeTrack))
- DisplayPM = menuItem(l="Preview Mesh", p = DisplayModeOptions)
- DisplayBB = menuItem(l="Bounding Box", p = DisplayModeOptions)
- DisplayModePM = rowColumnLayout(nc=1,p=ProxySettingsLayout, en=0)
- text(l="Display Percent",p=DisplayModePM)
- PcText = textField(tx="20",p=DisplayModePM, ec=Callback(SetSlider))
- PcTextSlider = floatSlider(dc=Callback(UpdateTextProxyDisplay),v=20,min = 1, max = 100, p= DisplayModePM,s=1)
- button1 = button(l="Make Proxies",bgc = [.1,8,.1], command=Callback(makeProxies), p=mainLayout)
- win.show()
- DisplayModeTrack()
Advertisement
Add Comment
Please, Sign In to add comment