Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. import pymel.core as pm
  2. import maya.cmds as c
  3. import shutil
  4. import random
  5.  
  6. global pathUrl
  7. pathUrl = ""
  8.  
  9. def deleteUi(*args):
  10. c.deleteUI("Lika Tool")
  11.  
  12. def BrowseButton(*args):
  13. global pathUrl
  14. askPath = c.fileDialog2(caption='select save file',fm=3,okCaption='save' ,dialogStyle=2)
  15. path = c.textField( "Saveto" ,edit = True , text = askPath[0])
  16. pathUrl = askPath[0]
  17. return pathUrl
  18.  
  19. def GrabTexture(*args):
  20. global pathUrl
  21. TextureFileList = []
  22. allFileNodes = cmds.ls(et="file")
  23. if len(pathUrl) <= 1:
  24. #Give Visual Clue that path is empty and open browser
  25. cmds.confirmDialog( title='Confirm', message='Hey Buddy, You still need to assign a Texture Folder', button=['Yes'], defaultButton='Yes')
  26. BrowseButton(*args) # if there is no Path Force Loadup Path
  27. path = pathUrl #update Path to path
  28.  
  29. for eachFile in allFileNodes:
  30. currentFile = cmds.getAttr("%s.fileTextureName" % eachFile)
  31. if currentFile not in TextureFileList:
  32. TextureFileList.append(currentFile)
  33.  
  34. for i in range(len(TextureFileList)):
  35. srcWindows =str(TextureFileList[i])
  36. fileSeqName= srcWindows.rsplit('/', 1)[-1]
  37. destWindows= str(path)+"/"+fileSeqName
  38. print "EXPORTED" + " " + destWindows
  39. cmds.sysFile(srcWindows, copy=destWindows)# Windows
  40.  
  41.  
  42. def createUI( pWindowTitle, pApplyCallback):
  43. if c.window("mainWin", exists = True):
  44. c.deleteUI("mainWin")
  45.  
  46. MainWindow = c.window("mainWin",t="Lika's Tool",w=400,h=600)
  47. c.columnLayout(adj = True)
  48. bannerPath= c.internalVar(upd=True)+"icons/bannerLika.jpg"
  49. c.image(w=400,h=80,image=bannerPath)
  50. c.separator(height=2,style='double')
  51. c.button("Object Info",h=50,c = "CheckObjectInfo()")
  52. c.button("Splatter Object",h=20,c = "SplatterRandom()")
  53. c.text(label = "Texture Folder: ")
  54. c.textField( "Saveto" ,text = "C:/",ed=False)
  55. c.button( "Browse" ,w = 100,h = 20, command = BrowseButton)
  56. c.button( "Export Textures" ,w = 100,h = 20,command = GrabTexture)
  57. def cancelCallback(*pArgs):
  58. if c.window("mainWin", exists = True):
  59. c.deleteUI("mainWin")
  60.  
  61. c.button( "Close" ,w = 100,h = 20, command = cancelCallback)
  62. c.showWindow(MainWindow)
  63.  
  64. def pApplyCallback(*pArgs):
  65. print('Button Pressed')
  66.  
  67.  
  68. def CheckObjectInfo():
  69. if c.window("ObjectInfo", exists = True):
  70. c.deleteUI("ObjectInfo")
  71.  
  72. result = c.ls(sl=True,long=True)
  73.  
  74.  
  75. if len(result):#only if there is a slection
  76. TriAmmount = cmds.polyEvaluate(result,t=True) #Grab Tri's
  77. FaceAmmount = cmds.polyEvaluate(result,f =True) #Grab Face's
  78. VerticesAmmount = cmds.polyEvaluate(result,v=True) #Grab Vertice's
  79. cmds.selectMode(co=True)
  80. cmds.selectType(smp=False,sme=True,smf=False,smu=False,pv=False,pe=True,pf=False,puv=False) #works
  81. cmds.polySelectConstraint( m=3, t=8, sz=3 ) # Select NGONS
  82. cmds.polySelectConstraint(disable=True)
  83. ngonsAmmount = cmds.polyEvaluate(fc=True)
  84.  
  85. ObjectInfo = c.window("ObjectInfo",t="Object Info")
  86. cmds.gridLayout( numberOfColumns=2, cellWidthHeight=(200,50))
  87. cmds.text(label="This Model got:",fn="boldLabelFont")
  88. cmds.text(label=str(TriAmmount)+" Tris",bgc=[0,255,0])
  89. cmds.text(label="")
  90. cmds.text(label=str(FaceAmmount)+" Faces",bgc=[0,255,0])
  91. cmds.text(label="")
  92. cmds.text(label=str(VerticesAmmount)+" Vertices",bgc=[0,255,0])
  93. def cancelCallback(*pArgs):
  94. if c.window("ObjectInfo", exists = True):
  95. c.deleteUI("ObjectInfo")
  96. cmds.button("Close",command = cancelCallback)
  97.  
  98. if ngonsAmmount == 0:
  99. cmds.text(label=str(ngonsAmmount)+" Ngons",bgc=[0,255,0])
  100. else:
  101. cmds.text(label=str(ngonsAmmount)+" Ngons",bgc=[255,0,0])
  102.  
  103. cmds.showWindow(ObjectInfo)
  104.  
  105.  
  106.  
  107. def SplatterRandom():
  108. random.seed(random.uniform(0,1800))
  109. result = c.ls(sl=True,long=True)
  110. transformName = result[0]
  111. instanceGroupName = c.group(em=True, name= transformName + '_instance_grp#')
  112.  
  113. for i in range(0,50):
  114. instanceResult = c.instance(transformName, name=transformName+ '_instance#')
  115. c.parent(instanceResult, instanceGroupName)
  116.  
  117. #Generate Random Positions And Rotation
  118. xPos = random.uniform(-10,10)
  119. yPos = random.uniform(-10,10)
  120. zPos = random.uniform(-10,10)
  121. xRot = random.uniform(0,360)
  122. yRot = random.uniform(0,360)
  123. zRot = random.uniform(0,360)
  124. size = random.uniform(0.4,1.5)
  125.  
  126. c.move( xPos,yPos,zPos, instanceResult)
  127. c.rotate( xRot,yRot,zRot, instanceResult)
  128. c.scale( size,size,size, instanceResult)
  129.  
  130. c.hide( transformName )
  131. c.xform( instanceGroupName, centerPivots=True )
  132. c.select(clear=True)
  133.  
  134.  
  135. createUI("likaTool",pApplyCallback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement