def Cas_MCW_restoreMisc(undoState , texWindowState): if undoState == 1: cmds.undoInfo(swf=1) if texWindowState == 1: texWin = cmds.getPanel(sty ="polyTexturePlacementPanel") cmds.textureWindow(texWin[0],e=1,id=1) cmds.progressWindow(ep=1)
def toggleGrid(): panel = mc.getPanel(withFocus=True) ptype = mc.getPanel(typeOf=panel) # if in UV Editor toggle the according grid there if ptype == 'scriptedPanel' and panel.startswith('polyTexturePlacementPanel'): state = mc.textureWindow(panel, q=True, tgl=True) mc.textureWindow(panel, e=True, tgl=not state) # else use these 2 grid toggelling methods to switch it for sure elif ptype == 'modelPanel': state = True if mc.grid(q=True, toggle=True) or mc.modelEditor(panel, q=True, grid=True): state = False mc.grid(toggle=state) mc.modelEditor(panel, e=True, grid=state)
def textureWindow(*args, **kwargs): if len(args): doPassSelf = kwargs.pop('passSelf', False) else: doPassSelf = False for key in ['cc', 'changeCommand']: try: cb = kwargs[key] if callable(cb): kwargs[key] = _factories.makeUICallback(cb, args, doPassSelf) except KeyError: pass res = cmds.textureWindow(*args, **kwargs) return res
def Cas_massCopyWeight_cmd(pruneValue,autoConvertRigid): """ Author : Saehoon Lee Date : 16/02/2009 Email : [email protected] http://www.castorlee.com Tested for Maya v8.5 v2008 v2009 Description : Python version of Cas_massCopyWeight. More stable and less code than mel. GUI added more functions related to rigid skin DO NOT DISTRIBUTE WITHOUT PERMISSION FROM AUTHOR How to use : ( v 4.0 ) run command in python script editor: import maya.cmds as cmds import Cas_massCopyWeight_python Cas_massCopyWeight_python.Cas_massCopyWeight_UI() Select source and Target objects/groups to transfer binding/weights the press buttons on GUI that you want to perform """ # Date: 17/07/2009 # V 4.0 : # minor bug fix , issue with Maya 2009 # # Date: 16/02/2009 # V 3.9 : # just realized that if rigid body's weight is less than 1 , resulted smooth skin weight of less than 1 (combined) # is going to move the vertices. With bit of help from Tom, managed to come up with workable version of the converter # # Date: 07/01/2009 # V 3.8 : # Fixed bug when root of joint is not joint node. (group node) Thanks Andrew # # Date: 27/11/2008 # V 3.7 : # Fixed iteration bug with Maya 8.5 implementation. # # Date: 05/11/2008 # V 3.6 : First GUI version with Rigid skin converter # Added GUI for normal weight copying function # Added function to convert rigid skin to smooth skin and copy the weights from rigid to smooth skin # Added option to toggle auto delete rigid joint cluster and auto convert rigid skin to smooth skin # Added additional function to delete rigid skin jointcluster if wanted # Converting from rigid skin to smooth skin does not delete rigid skin jointcluster by default. # But the weights of rigid skin jointCluster is set to 0 after copying the weight to new smooth skinCluster # # More error checking. Better progress bar. Implemented own function for deleteunusedinfluence # # Date: 03/11/2008 # V 3.5 : Non Pymel version # Pymel was used last version of this sctipt to simplify the process and shorten the code. # But this led to some complication of distributing to the other studios. # Therefore removed Pymel commands and used native # Maya commands only. Implemented few of own functions that does not exist in Python commands in Maya. # # Date: 15/10/2008 # V 3.4 : First Python version of the script # Python version seems to be more stable and works better. # Added more rigrious error checking prune small weight function. Modified the way it works by changing the command # # Date: 09/10/2008 # V 3.3 : Changed prune small weight method. # there was heavy memory leak bug with Maya when UV editor is open and run default # prune small weight function. Modified the way it works by changing the command to # skinPercent -prw 0.01 ClusterName. Faster and with no memory leak. Also minimised doing # lots of selections. Apprently there is another bug or stupid feature in Maya where Texture UV # editor keeps the cache of displayed images, so if you do lots of selection it will eat memory # and significantly slow down the process. Known Maya behaviour. # # Date: 14/09/2008 # V 3.2 : Changed bonding option. Removed cloest joint option which was not # working well with the joints with the same position. # # Date: 15/02/2008 # V 3.1 : Changed how removing unused influence work. This fixes weird # flashing mouse icon issue with Evaldeferred command. But less intuative. # # Date: 18/01/2008 # V 3.0 : Uses Maya's copyweight function more wisely and now it # is possible to map the objects without the same names. but slower. # It is possible to make this bit faster, but don't want to start # modifying the user's skin binding, copy weight settings. # # Date: 15/01/2008 # V 2.0 : Version 2 works with groups of objects too. Meshes needs # to have the same names to work. # # Date: 1/10/2007 # V 1.0 : First version # Select source and destination mesh and it will bind the relevent # joints and copy weights across. # time = cmds.timerX() time2 = 0 timeTook2 = 0 progressCount = 0 sel = cmds.ls(sl=True , tr= 1) if (sel == None) or (sel == []): Cas_IO.Cas_printWarning ("Please select one object for source and at least one object/groups for target...") return if len(sel) < 2: Cas_IO.Cas_printWarning ("Please select one objects for source and at least one object/groups for target...") return warningCount = 0 undoState = cmds.undoInfo(q = 1 , st = 1) texWin = cmds.getPanel(sty ="polyTexturePlacementPanel") texState = cmds.textureWindow(texWin[0],q=1,id=1) cmds.progressWindow(min=0 , max=100 , t = "Cas_massCopyWeight_Python 3.6") cmds.textureWindow(texWin[0],q=1,id=0) #disable undo for memory issue cmds.undoInfo(swf=0) #print rootjoint #print "done" #return # compile both source and target node lists org = [] rel = cmds.listRelatives(sel[0],ad = 1,pa =1 , typ="transform") if rel != None: org = rel org.append(sel[0]) #print org #org.append(sel[0]) source = org[:] # make a copy #find mesh only for node in org : shape = cmds.listRelatives(node , s=1 , type = "mesh",pa=1) if shape == None: #print "opps no mesh shape node has been found for node : %s" % node #print node source.remove(node); #convert to soft skin if necessary if autoConvertRigid == True: #need some sort of warning system .. here ? result = Cas_convertRigidToSmooth.Cas_convertRigidToSmooth_cmd(source) if result[1] == 0: Cas_IO.Cas_printInfo("%s rigid skin converted to smooth skin" %result[0]) else: Cas_IO.Cas_printWarning("%s rigid skin converted to smooth skin with %s warnings. please check your script editor" %(result[0],result[1])) autoDelete = cmds.checkBox(Cas_MCW_autoDeleteJointClusterCheckCT,q=True,v=True) if autoDelete == True: time2 = cmds.timerX() confirm = cmds.confirmDialog( title="Delete rigid joint clusters" , message="It will disconnect the other objects bind to the deleted clusters as well"+"\n"\ +" Are you sure?", button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' ) timeTook2 = cmds.timerX(st=time2) if confirm == "Yes": Cas_convertRigidToSmooth.Cas_CRTS_deleteJointCluster(source) print "copying smooth skin weights now..." progressCount = 10 cmds.progressWindow(e=1,pr=progressCount) #now finally check to see if objects actually has skinCluster org = source[:] for node in org: if Cas_MCW_findRelatedSkinSluster(node) == None: print "No skincluster found for node. Removed from list : %s" %node warningCount = warningCount +1 source.remove(node) # find the root joint to bind to. joints =[] try: joints = cmds.skinCluster(sel[0], q=1 , inf = 1) except Exception, msg: Cas_IO.Cas_printWarning("None of the source objects seems to have skin cluster! (or it is rigid skin and not converted to smooth skin) %s" % msg) Cas_MCW_restoreMisc(undoState,texState) return