cwisbg

Rs ProxyMaker

Mar 21st, 2019
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.61 KB | None | 0 0
  1. #Proxy maker
  2. # v1.2
  3. from pymel.core import *
  4. import os
  5. def getMat(s):# get material from selected
  6.     matSG = s.getShape().listConnections(t="shadingEngine")
  7.     mat = ls(listConnections(matSG),materials=1)
  8.     return matSG, mat
  9. def assMat(s,matSG,mat):
  10.     try:
  11.         sets(matSG, e=1, forceElement = s)
  12.         print "material added"
  13.     except:
  14.         try:
  15.             hyperShade(s, a = mat)
  16.             print "material assigned"
  17.         except:
  18.             select(s,add=1)
  19.             print "could not assign material to:", s
  20. def getPath():
  21.     w = workspace(act=1, q=1)
  22.     filePath= fileDialog2(dir = w, ds=1, fm = 2)
  23.     if filePath:
  24.         filePathTxt.setText(filePath[0].replace("\\","/") )
  25.     return filePath
  26.    
  27. def makeProxies():
  28.     filePath = filePathTxt.getText()
  29.     matList = []
  30.     StartFrame = startFrameTxt.getText()
  31.     EndFrame = endFrameTxt.getText()
  32.     ByFrameAmnt = ByFrameAmntTxt.getText()
  33.     if DoNewFolderCheck.getValue() == True:
  34.         filePath = filePath+"/"+ str(NewFolderNameText.getText())
  35.         make_dir(filePath)
  36.     filePathS = filePath
  37.     childCheck = []
  38.     sl = selected()
  39.     select(cl=1)
  40.     #progWin = progressWindow(isInterruptable=1, t= "Exporting...", min = 0, max = len(sl))
  41.     i = 0
  42.     for ss in sl:
  43.         #filePath = filePathTxt.getText()
  44.         #progressWindow(progWin, edit=True, pr = i)
  45.  
  46.  
  47.        
  48.         if DoSubFolderCheck.getValue() == True:
  49.             filePath = filePathS+"/"+ str(ss+"_proxy_")
  50.             make_dir(filePath)
  51.        
  52.         print "Exporting to "+  filePath
  53.         setAttr(ss.visibility,1)
  54.         if DoAnimCheck.getValue():
  55.             select(ss)
  56.             rsProxy(fp =filePath+"/"+ss+".rs",b= float(ByFrameAmnt), sl=1, s=int(StartFrame), e = int(EndFrame))
  57.             print "Exporting Animation"
  58.         else:
  59.             select(ss)
  60.             rsProxy(fp =filePath+"/"+ss+".rs", sl=1)
  61.         select(cl=1)
  62.         rsProxyNode = createNode("RedshiftProxyMesh",n = ss+"_"+ObjectNameText.getText()+"_proxy")
  63.         rsProxyMesh = createNode("mesh",n = ss+"_"+ObjectNameText.getText()+"Shape")
  64.         rsProxyNode.outMesh >> rsProxyMesh.inMesh
  65.    
  66.         setAttr(rsProxyNode.fileName, filePath+"\\"+ss+".rs")
  67.        
  68.         if UseMaterial.getValue():
  69.             print "Use material"
  70.             childCheck = ss.listRelatives(c=1)# see if its a group
  71.             if len(childCheck) < 2:
  72.                 matSG, mat = getMat(ss)
  73.                 assMat(rsProxyMesh,matSG[0],mat)
  74.             else:
  75.                 assMat(rsProxyMesh,"initialShadingGroup","initialShadingGroup")
  76.         proxy = listConnections(rsProxyMesh, t="RedshiftProxyMesh")[0]
  77.         if DoAnimCheck.getValue():
  78.             setAttr(proxy + ".useFrameExtension", 1)
  79.             pp = "####"
  80.             setAttr(rsProxyNode.fileName, filePath+"\\"+ss+"."+pp+".rs")
  81.         displayModeState = 0    
  82.         proxyState = DisplayModeOptions.getValue()
  83.         if(proxyState == "Bounding Box"):
  84.             displayModeState = 0
  85.         if(proxyState == "Preview Mesh"):
  86.             displayModeState = 1  
  87.             pcValue = PcText.getText()
  88.             setAttr(proxy + ".displayPercent", int(pcValue))          
  89.         setAttr(proxy + ".displayMode", displayModeState)
  90.         if HideOriginalCheck.getValue() == 1:
  91.             setAttr(ss+".visibility", 0)  
  92.  
  93.         ObjId = 0
  94.         if ObjectIdOverrideCheck.getValue() == True:
  95.             ObjId = int(ObjIdText.getText())
  96.             setAttr(rsProxyNode +".objectIdMode", 1)
  97.             setAttr(rsProxyMesh +".rsObjectId", ObjId)
  98.         """    
  99.        else:
  100.            if len(childCheck) < 2:
  101.                ObjId = getAttr(ss+".rsObjectId")
  102.        """  
  103.        
  104.         """
  105.        if progressWindow(progWin, query=1, isCancelled=1):
  106.            print "killed at",ss, i+1
  107.            break
  108.        """    
  109.         i += 1    
  110.            
  111.     progressWindow(progWin, endProgress=1)      
  112.      
  113. def AnimationExportState():
  114.     FrameRangeLayout.setEnable(DoAnimCheck.getValue())
  115. def UpdateTextProxyDisplay():
  116.     PCValue = PcTextSlider.getValue()
  117.     PcText.setText(str(int(PCValue)))
  118.    
  119. def DisplayModeTrack():
  120.     proxyState = DisplayModeOptions.getValue()
  121.     if(proxyState == "Bounding Box"):
  122.         DisplayModePM.setEnable(0)
  123.     if(proxyState == "Preview Mesh"):
  124.         DisplayModePM.setEnable(1)
  125. def SetSlider():
  126.     pcValue = PcText.getText()
  127.     PcTextSlider.setValue(float(pcValue))  
  128. def ObjIDState():
  129.     ObjIdText.setEnable(ObjectIdOverrideCheck.getValue())
  130. def make_dir(path):
  131.     """
  132.    input a path to check if it exists, if not, it creates all the path
  133.    :return: path string
  134.    """
  135.     if not os.path.exists(path):
  136.         os.makedirs(path)
  137.     return path
  138. def NewFolderName():
  139.     FolderCheckLayout.setEnable(DoNewFolderCheck.getValue())
  140.  
  141. # GUI
  142.  
  143. try:  
  144.     if(window(win, exists=True)):
  145.         deleteUI(win)
  146. except:
  147.     pass   
  148.    
  149. win = window(title= "ProxyMaker", s=1)
  150. mainLayout = rowColumnLayout(nc=1)
  151. text(l="Redshift Proxy Creator",p=mainLayout)
  152. text(l=" ",p=mainLayout)
  153. # File path
  154. FilePathLayout = rowColumnLayout(nc=1, p=mainLayout)
  155. text(l="File Path",p=FilePathLayout,al="left")
  156. filePathTxt = textField(p=FilePathLayout,w = 200)
  157. w = workspace(act=1, q=1)
  158. filePathTxt.setText(w)
  159. getPathBtn = button(l="get path", command=Callback(getPath))
  160.  
  161. # New folder
  162. DoNewFolderCheck = checkBox(l="MakeNewFolder",p=mainLayout, cc=Callback(NewFolderName),v=1)
  163. FolderCheckLayout = rowColumnLayout(nc=2, p= mainLayout, en=1)
  164. text(l="Folder name",p=FolderCheckLayout)
  165. NewFolderNameText = textField(tx="_ProxyExport_",p=FolderCheckLayout, w=100)
  166. DoSubFolderCheck = checkBox(l="MakeSubFolders",p=FolderCheckLayout)
  167.  
  168. # Animation
  169. DoAnimCheck = checkBox(l="Export Animation",p=mainLayout, cc=Callback(AnimationExportState))
  170. FrameRangeLayout = rowColumnLayout(nc=3, p=mainLayout, en=0)
  171. text(l="Frame Range",p=FrameRangeLayout)
  172. startFrameGet = int(playbackOptions(min=1,q=1))
  173. endFrameGet = int(playbackOptions(max=1,q=1))
  174. startFrameTxt = textField(tx=str(startFrameGet),w=50,p=FrameRangeLayout)
  175. endFrameTxt = textField(tx=str(endFrameGet),w=50,p=FrameRangeLayout)
  176. text(l="By Frame",p=FrameRangeLayout)
  177. ByFrameAmntTxt = textField(tx=1,w=50,p=FrameRangeLayout)
  178.  
  179. # Settings proxyMeshShape"
  180. ProxySettingsLayout = frameLayout(bgc = [.2,.3,.5], en = 1, label='Proxy Settings', cll =1, cl=1,p= mainLayout  )
  181. ObjectNameLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
  182. text(l="ObjName_+",p=ObjectNameLayout)
  183. ObjectNameText = textField(tx="proxyMesh",p=ObjectNameLayout, w=150)
  184. UseMaterial = checkBox(l="Use Material", p=ProxySettingsLayout, v=1)
  185. HideOriginalCheck = checkBox(l="Hide original" ,p=ProxySettingsLayout,v=1)
  186.  
  187. #object id
  188. ObjIDLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
  189. ObjectIdOverrideCheck = checkBox(l="Object ID", p=ObjIDLayout, v=0, cc=Callback(ObjIDState))
  190. ObjIdText = textField(tx="1",p=ObjIDLayout, w=50)
  191.  
  192. # Display mode
  193. DispModeLayout = rowColumnLayout(nc=3, p=ProxySettingsLayout, en=1)
  194. text(l = "Display Mode",p=DispModeLayout,al="left")
  195. DisplayModeOptions = optionMenu(p=DispModeLayout, cc=Callback(DisplayModeTrack))
  196. DisplayPM = menuItem(l="Preview Mesh", p = DisplayModeOptions)
  197. DisplayBB = menuItem(l="Bounding Box", p = DisplayModeOptions)
  198.  
  199.  
  200. DisplayModePM = rowColumnLayout(nc=1,p=ProxySettingsLayout, en=0)
  201. text(l="Display Percent",p=DisplayModePM)
  202. PcText = textField(tx="20",p=DisplayModePM, ec=Callback(SetSlider))
  203. PcTextSlider = floatSlider(dc=Callback(UpdateTextProxyDisplay),v=20,min = 1, max = 100, p= DisplayModePM,s=1)
  204.  
  205. button1 = button(l="Make Proxies",bgc = [.1,8,.1], command=Callback(makeProxies), p=mainLayout)
  206.  
  207.  
  208. win.show()
  209.  
  210. DisplayModeTrack()
Advertisement
Add Comment
Please, Sign In to add comment