Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymel.core as pm
- import maya.cmds as c
- import shutil
- import random
- global pathUrl
- pathUrl = ""
- def deleteUi(*args):
- c.deleteUI("Lika Tool")
- def BrowseButton(*args):
- global pathUrl
- askPath = c.fileDialog2(caption='select save file',fm=3,okCaption='save' ,dialogStyle=2)
- path = c.textField( "Saveto" ,edit = True , text = askPath[0])
- pathUrl = askPath[0]
- return pathUrl
- def GrabTexture(*args):
- global pathUrl
- TextureFileList = []
- allFileNodes = cmds.ls(et="file")
- if len(pathUrl) <= 1:
- #Give Visual Clue that path is empty and open browser
- cmds.confirmDialog( title='Confirm', message='Hey Buddy, You still need to assign a Texture Folder', button=['Yes'], defaultButton='Yes')
- BrowseButton(*args) # if there is no Path Force Loadup Path
- path = pathUrl #update Path to path
- for eachFile in allFileNodes:
- currentFile = cmds.getAttr("%s.fileTextureName" % eachFile)
- if currentFile not in TextureFileList:
- TextureFileList.append(currentFile)
- for i in range(len(TextureFileList)):
- srcWindows =str(TextureFileList[i])
- fileSeqName= srcWindows.rsplit('/', 1)[-1]
- destWindows= str(path)+"/"+fileSeqName
- print "EXPORTED" + " " + destWindows
- cmds.sysFile(srcWindows, copy=destWindows)# Windows
- def createUI( pWindowTitle, pApplyCallback):
- if c.window("mainWin", exists = True):
- c.deleteUI("mainWin")
- MainWindow = c.window("mainWin",t="Lika's Tool",w=400,h=600)
- c.columnLayout(adj = True)
- bannerPath= c.internalVar(upd=True)+"icons/bannerLika.jpg"
- c.image(w=400,h=80,image=bannerPath)
- c.separator(height=2,style='double')
- c.button("Object Info",h=50,c = "CheckObjectInfo()")
- c.button("Splatter Object",h=20,c = "SplatterRandom()")
- c.text(label = "Texture Folder: ")
- c.textField( "Saveto" ,text = "C:/",ed=False)
- c.button( "Browse" ,w = 100,h = 20, command = BrowseButton)
- c.button( "Export Textures" ,w = 100,h = 20,command = GrabTexture)
- def cancelCallback(*pArgs):
- if c.window("mainWin", exists = True):
- c.deleteUI("mainWin")
- c.button( "Close" ,w = 100,h = 20, command = cancelCallback)
- c.showWindow(MainWindow)
- def pApplyCallback(*pArgs):
- print('Button Pressed')
- def CheckObjectInfo():
- if c.window("ObjectInfo", exists = True):
- c.deleteUI("ObjectInfo")
- result = c.ls(sl=True,long=True)
- if len(result):#only if there is a slection
- TriAmmount = cmds.polyEvaluate(result,t=True) #Grab Tri's
- FaceAmmount = cmds.polyEvaluate(result,f =True) #Grab Face's
- VerticesAmmount = cmds.polyEvaluate(result,v=True) #Grab Vertice's
- cmds.selectMode(co=True)
- cmds.selectType(smp=False,sme=True,smf=False,smu=False,pv=False,pe=True,pf=False,puv=False) #works
- cmds.polySelectConstraint( m=3, t=8, sz=3 ) # Select NGONS
- cmds.polySelectConstraint(disable=True)
- ngonsAmmount = cmds.polyEvaluate(fc=True)
- ObjectInfo = c.window("ObjectInfo",t="Object Info")
- cmds.gridLayout( numberOfColumns=2, cellWidthHeight=(200,50))
- cmds.text(label="This Model got:",fn="boldLabelFont")
- cmds.text(label=str(TriAmmount)+" Tris",bgc=[0,255,0])
- cmds.text(label="")
- cmds.text(label=str(FaceAmmount)+" Faces",bgc=[0,255,0])
- cmds.text(label="")
- cmds.text(label=str(VerticesAmmount)+" Vertices",bgc=[0,255,0])
- def cancelCallback(*pArgs):
- if c.window("ObjectInfo", exists = True):
- c.deleteUI("ObjectInfo")
- cmds.button("Close",command = cancelCallback)
- if ngonsAmmount == 0:
- cmds.text(label=str(ngonsAmmount)+" Ngons",bgc=[0,255,0])
- else:
- cmds.text(label=str(ngonsAmmount)+" Ngons",bgc=[255,0,0])
- cmds.showWindow(ObjectInfo)
- def SplatterRandom():
- random.seed(random.uniform(0,1800))
- result = c.ls(sl=True,long=True)
- transformName = result[0]
- instanceGroupName = c.group(em=True, name= transformName + '_instance_grp#')
- for i in range(0,50):
- instanceResult = c.instance(transformName, name=transformName+ '_instance#')
- c.parent(instanceResult, instanceGroupName)
- #Generate Random Positions And Rotation
- xPos = random.uniform(-10,10)
- yPos = random.uniform(-10,10)
- zPos = random.uniform(-10,10)
- xRot = random.uniform(0,360)
- yRot = random.uniform(0,360)
- zRot = random.uniform(0,360)
- size = random.uniform(0.4,1.5)
- c.move( xPos,yPos,zPos, instanceResult)
- c.rotate( xRot,yRot,zRot, instanceResult)
- c.scale( size,size,size, instanceResult)
- c.hide( transformName )
- c.xform( instanceGroupName, centerPivots=True )
- c.select(clear=True)
- createUI("likaTool",pApplyCallback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement