Advertisement
Guest User

Untitled

a guest
Jul 28th, 2019
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.48 KB | None | 0 0
  1. import maya.cmds as mc
  2.  
  3. #Center the pivot on all selected objects
  4. def centerPivot():
  5.     objectList = mc.ls(selection = True)
  6.    
  7.     if len(objectList) > 0:
  8.        
  9.         for object in objectList:
  10.            
  11.             mc.xform (object, cp = True,)
  12.     else:
  13.         print 'Please select the object or objects you would like to center the pivot on'
  14.  
  15. #Combine multiple meshes into one
  16. def combineMeshes():
  17.     selectedObjects = mc.ls(orderedSelection = True)    
  18.     currentUnitedPoly = selectedObjects[0]
  19.    
  20.     if(len(selectedObjects) > 1):    
  21.         mc.polyUnite(selectedObjects[0:len(selectedObjects)], name = 'Combined Mesh_#', ch = False, mergeUVSets = 1, centerPivot = True)
  22.     else:
  23.         print "Please select more than one object"    
  24.    
  25. #Conforms all normals to the most popular normal direction
  26. def conformNormals():
  27.    
  28.     objectList = mc.ls(selection = True)
  29.    
  30.     if len(objectList) > 0:
  31.        
  32.         for object in objectList:
  33.            
  34.             mc.polyNormal(object, normalMode = 2, userNormalMode = 0, ch = True)
  35.     else:
  36.         print 'Please select the object or objects you would like to conform normals on'
  37.  
  38. #Harden the selected edges
  39. def hardenEdge():
  40.     selectedObjects = mc.ls(orderedSelection = True)
  41.     onlyEdges = mc.filterExpand(selectedObjects, sm= 32)
  42.     mc.polySoftEdge (onlyEdges[0:len(onlyEdges)], a = 0, ch = 1)
  43.  
  44. #Soften selected edges
  45. def softenEdge():
  46.     selectedObjects = mc.ls(orderedSelection = True)
  47.     onlyEdges = mc.filterExpand(selectedObjects, sm= 32)
  48.     mc.polySoftEdge (onlyEdges[0:len(onlyEdges)], a = 180, ch = 1)
  49.        
  50. #Fills all holes in an object
  51. def fillHoles():
  52.    
  53.     objectList = mc.ls(selection = True)
  54.    
  55.     if len(objectList) > 0:
  56.        
  57.         for object in objectList:
  58.            
  59.             mc.polyCloseBorder(object, ch = True)
  60.     else:
  61.         print 'Please select the object or objects you would like to conform normals on'
  62.  
  63. #Apply an aim constraint to 2 objects
  64. def aimConstrain():
  65.     selectedObjects = mc.ls(orderedSelection = True)
  66.    
  67.     if(len(selectedObjects) != 2):
  68.         print 'Please only select 2 objects'
  69.        
  70.     else:
  71.         cmds.aimConstraint( selectedObjects[0], selectedObjects[1],  aimVector=[1, 0, 0], name='object_aimConstraint_#')
  72.  
  73. #Apply a point constraint to 2 objects and determine if you want to maintain the offset on the objects            
  74. def pointConstrain():
  75.     selectedObjects = mc.ls(orderedSelection = True)
  76.    
  77.     mop = mc.checkBox('mop', query = True, value = True)
  78.     if(len(selectedObjects) != 2):
  79.         print 'Please only select 2 objects'
  80.        
  81.     else:
  82.         cmds.pointConstraint( selectedObjects[0], selectedObjects[1],  mo = mop, weight = 1, name='object_pointConstraint_#')
  83.  
  84. #Merge polygon verts dependent upon the set Threshold value                    
  85. def mergeVertex():
  86.  
  87.     selectedObjects = mc.ls(orderedSelection = True)
  88.     onlyVertices = mc.filterExpand(selectedObjects, sm=31)
  89.    
  90.     threshold = mc.floatSliderGrp('Threshold', query = True, value = True)
  91.    
  92.     if(len(onlyVertices) == 1):
  93.         mc.polyMergeVertex (onlyVertices, d = threshold, am = 1, ch = 1)
  94.     else:  
  95.         mc.polyMergeVertex (onlyVertices[0:len(onlyVertices)], d = threshold, am = 1, ch = 1)
  96.  
  97. def deleteHistory():
  98.      selectedObjects = mc.ls(selection = True)
  99.      for object in selectedObjects:
  100.          mc.delete(object, ch = True)
  101.                                                            
  102. def freezeTransform():
  103.      selectedObjects = mc.ls(selection = True)
  104.      for object in selectedObjects:
  105.          mc.makeIdentity(object, apply = True, t = 1, r = 1, s = 1, n = 0, pn = 1)
  106.  
  107. def allThree():
  108.     centerPivot()
  109.     deleteHistory()
  110.     freezeTransform()
  111.                                  
  112. def createToolKitWindow():
  113.    
  114.     if mc.window('Georges_Tool_Kit', exists = True):
  115.         mc.deleteUI('Georges_Tool_Kit')
  116.    
  117.     mc.window('Georges_Tool_Kit', widthHeight = (500, 400), s = False)
  118.    
  119.     mc.columnLayout(adjustableColumn = True)
  120.     mc.text(label = "George's Tool Kit", height = 50, font = 'boldLabelFont', bgc = [0.5, 0.5, 0.9])
  121.     mc.separator (h=10, style = 'none')
  122.     mc.separator (h=10, style = 'none')
  123.  
  124.     mc.button(label = 'Combine Meshes', command = 'combineMeshes()')
  125.     mc.button(label = 'Conform Normals', command = 'conformNormals()')
  126.     mc.button(label = 'Harden Edge', command = 'hardenEdge()')
  127.     mc.button(label = 'Soften Edge', command = 'softenEdge()')
  128.     mc.button(label = 'Fill Holes', command = 'fillHoles()')
  129.     mc.button(label = 'Aim Constrain', command = 'aimConstrain()')
  130.     mc.button(label = 'Point Constrain', command = 'pointConstrain()')
  131.     mc.separator (h=10, style = 'none')
  132.     mc.checkBox('mop', label = 'Maintain Offset', align = 'center')
  133.     mc.separator (h=10, style = 'none')
  134.     mc.button(label = 'Merge Vertex', command = 'mergeVertex()')
  135.     mc.separator (h=10, style = 'none')
  136.     mc.floatSliderGrp('Threshold', label = 'Threshold', field = True, minValue = 0, value = 10)
  137.     mc.separator (h=10, style = 'none')
  138.     mc.button(label = 'Center Pivot', command = 'centerPivot()')
  139.     mc.button(label = 'Delete History', command = 'deleteHistory()')
  140.     mc.button(label = 'Freeze Transformations', command = 'freezeTransform()')
  141.     mc.button(label = 'CP + DH + FT', command = 'allThree()')
  142.     mc.window('Georges_Tool_Kit', widthHeight = (500, 425), e = True)
  143.     mc.showWindow('Georges_Tool_Kit')
  144.    
  145. createToolKitWindow()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement