frommayaimportcmdsdefcheckProgressEscape():# check if dialog has been cancelledcancelled=cmds.progressWindow(query=True,isCancelled=True)ifcancelled:cmds.progressWindow(endProgress=1)returncancelleddefgetAllParticlesDictionary(shape):cmds.progressWindow(title='Fetch Particle Data',progress=0,status='Fetched: 0%',isInterruptable=True)ptcsDict={}minFrames=int(cmds.playbackOptions(q=True,min=True))maxFrames=int(cmds.playbackOptions(q=True,max=True))nFrames=float(maxFrames-minFrames)# better use the actual range, since you queried the playback optionsforcurrentFrameinrange(minFrames,maxFrames):ifcheckProgressEscape():returnamount=100.0/nFrames*(currentFrame-minFrames+1)cmds.progressWindow(edit=True,progress=amount,status='Fetched: %d%%'%amount)# cmds.pause(seconds=.001)cmds.currentTime(currentFrame,update=True,edit=True)forparticleCountinxrange(cmds.particle(shape,q=True,ct=True)):particleId=int(cmds.particle(shape,q=True,order=particleCount,at='id')[0])# better check the key exists first, then add your logicifparticleIdnotinptcsDict.keys():ptcsDict[particleId]={}ptcsDict[particleId][currentFrame]=cmds.particle(shape,q=True,order=particleCount,at='position')cmds.progressWindow(endProgress=1)returnptcsDictdefcurvesFromParticle(ptcsDict):cmds.progressWindow(title='Build Curves',progress=0,status='Building Curves: 0%',isInterruptable=True)# this section had to be de-indentedemptyFolder=cmds.group(em=True,n="Curves")ptcCount=len(ptcsDict)fori,(curveParticleId,data)inenumerate(ptcsDict.iteritems()):ifcheckProgressEscape():returnsortedKeyFrameList=sorted(data.keys())pointList=[]forkeyFrameinsortedKeyFrameList:pointList.append(ptcsDict[curveParticleId][keyFrame])curveObj=cmds.curve(name="pCurve%d"%curveParticleId,p=pointList)locators=cmds.spaceLocator(name="locator%d"%curveParticleId)cmds.pathAnimation(locators,stu=sortedKeyFrameList[0],etu=sortedKeyFrameList[-1],c=curveObj)# place all objects in Group called Curvescmds.parent(curveObj,emptyFolder)cmds.delete(locators)amount=100/ptcCount*float(i)cmds.progressWindow(edit=True,progress=amount,status='Building Curves: %d%%'%amount)cmds.progressWindow(endProgress=1)ptcs=cmds.ls(typ='nParticle')forshapeinptcs:cmds.setAttr("%s.lifespanMode"%(shape,),2)cmds.setAttr("%s.maxCount"%(shape,),100)cmds.setAttr("%s.lifespanRandom"%(shape,),3)ptcDict=getAllParticlesDictionary(shape)ifnotptcDict:print'data was not be fetched for %s; skipped'%(shape,)continuecurvesFromParticle(ptcDict)
maya python 创建窗口_如何在Maya中通过Python创建进度窗口?
最新推荐文章于 2023-03-08 13:42:24 发布