Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.48 KB | None | 0 0
  1. import maya.cmds as cmds
  2.  
  3. #Must have ** selectedd:
  4. def popUpSlct():
  5. if cmds.window("SelectSmth", query=True, exists=True):
  6. cmds.deleteUI("SelectSmth", window=True)
  7. else:
  8. slctWindow = cmds.window('SelectSmth', title="Selector Alert Pop Up Prevention Task Force", width=180, )
  9. cmds.columnLayout(rowSpacing=10, )
  10. cmds.text(label='! MUST SELECT CONTROLLER !', width=180, )
  11. cmds.button(label='Ok', align="center", command=('mc.deleteUI(\"'+slctWindow+'\", window=True)'), width=180, )
  12. cmds.showWindow(slctWindow)
  13.  
  14. #Delete window if existing:
  15. if cmds.window("toolBox_window", query=True, exists=True):
  16. cmds.deleteUI("toolBox_window", window=True)
  17.  
  18. #Manip Creation:
  19. def manipCreation(*arg):
  20. jointSelected = cmds.ls(sl=True, )
  21. n = 0
  22.  
  23. if jointSelected:
  24. for n in jointSelected:
  25. jointName = (n[2:])
  26. jointTransVal = cmds.xform(n, query=True, translation=True, worldSpace=True)
  27. jointRotVal = cmds.xform(n, query=True, rotation=True)
  28. manip = cmds.circle(nr=(0,1,0), n="c%s" %jointName)
  29. cmds.xform(manip[0], translation=jointTransVal, worldSpace=True)
  30. cmds.xform(manip[0], rotation=jointRotVal, worldSpace=True)
  31. else :
  32. cmds.circle(nr=(0,1,0), n="c_manip_01")
  33.  
  34. #Shape Renamer:
  35.  
  36. def renamer(*arg):
  37. newName = cmds.textFieldGrp(nameChosen, q=1, text=1)
  38. listObj = cmds.ls(sl=True)
  39. objSlctd = len(listObj)
  40. if objSlctd != 1:
  41. print ('Nothing Selected')
  42. else:
  43. cmds.rename( listObj, newName )
  44.  
  45. #Change manip's shape:
  46.  
  47. def manipCircle(*arg):
  48. k = 0
  49. oldManipShape = cmds.listRelatives(shapes=True)
  50. manip = cmds.ls(selection = True)
  51. shpSlctd = len(manip)
  52. if shpSlctd ==0:
  53. popUpSlct()
  54. print ('Nothing Selected')
  55. else:
  56. for n in manip:
  57. manipAll = cmds.ls(selection = True)
  58. cmds.select(manip[k])
  59. trgtTranslate = cmds.xform( query=True, translation=True, worldSpace=True, )
  60. trgtRotate = cmds.xform( query=True, rotation=True, worldSpace=True, )
  61. circleManip = cmds.circle(nr=(0,1,0), )
  62. cmds.xform(circleManip[0], translation=trgtTranslate, worldSpace=True, )
  63. cmds.xform(circleManip[0], rotation=trgtRotate, )
  64. newManip = cmds.ls(sl=True)[0]
  65. newManipShape = cmds.listRelatives(shapes=True)
  66. cmds.select(newManipShape, manip[k] )
  67. cmds.parent(relative=True, shape=True)
  68. cmds.delete(oldManipShape[k])
  69. cmds.rename(newManipShape, oldManipShape[k])
  70. cmds.delete(newManip)
  71. k+=1
  72. cmds.select(manip)
  73. print 'circle'
  74.  
  75. def manipSquare(*arg):
  76. k = 0
  77. manip = cmds.ls(selection = True)
  78. oldManipShape = cmds.listRelatives(shapes=True)
  79. shpSlctd = len(manip)
  80. if shpSlctd ==0:
  81. popUpSlct()
  82. print ('Nothing Selected')
  83. else:
  84. for n in manip:
  85. manipAll = cmds.ls(selection = True)
  86. cmds.select(manip[k])
  87. trgtTranslate = cmds.xform(query=True, translation=True, worldSpace=True, )
  88. trgtRotate = cmds.xform(query=True, rotation=True, worldSpace=True, )
  89. squareManip = cmds.circle(nr=(0,1,0), degree = 1, sections = 4, )
  90. squareShape = cmds.listRelatives(squareManip, shapes=True)
  91. squareTranform = cmds.listRelatives(squareShape, parent=True)
  92. cmds.move(-1, 0, 1, squareTranform[0] + ".cv[1]")
  93. cmds.move(1, 0, 1, squareTranform[0] + ".cv[0]" , squareTranform[0] + ".cv[4]")
  94. cmds.move(-1, 0, -1, squareTranform[0] + ".cv[2]")
  95. cmds.move(1, 0, -1, squareTranform[0] + ".cv[3]")
  96. cmds.xform(squareManip[0], translation=trgtTranslate, worldSpace=True, )
  97. cmds.xform(squareManip[0], rotation=trgtRotate, )
  98. newManip = cmds.ls(sl=True)[0]
  99. newManipShape = cmds.listRelatives(shapes=True)
  100. cmds.select(newManipShape, manip[k] )
  101. cmds.parent(relative=True, shape=True)
  102. cmds.delete(oldManipShape[k])
  103. cmds.rename(newManipShape, oldManipShape[k])
  104. cmds.delete(newManip)
  105. k+=1
  106. cmds.select(manip)
  107. print 'square'
  108.  
  109. def manipTriangle(*arg):
  110. manip = cmds.ls(selection = True)
  111. oldManipShape = cmds.listRelatives(shapes=True)
  112. trgtTranslate = cmds.xform(query=True, translation=True, worldSpace=True, )
  113. trgtRotate = cmds.xform(query=True, rotation=True, worldSpace=True, )
  114. triangleManip = cmds.circle(nr=(0,1,0), degree = 1, sections = 3, )
  115. triangleShape = cmds.listRelatives(triangleManip, shapes=True)
  116. triangleTranform = cmds.listRelatives(triangleShape, parent=True)
  117. cmds.xform(triangleManip, translation=trgtTranslate, worldSpace=True, )
  118. cmds.xform(triangleManip, rotation=trgtRotate, )
  119. newManip = cmds.ls(sl=True)[0]
  120. newManipShape = cmds.listRelatives(shapes=True)
  121. cmds.select(newManipShape, manip )
  122. cmds.parent(relative=True, shape=True)
  123. cmds.delete(oldManipShape)
  124. cmds.rename(newManipShape, oldManipShape)
  125. cmds.delete(newManip)
  126. cmds.select(manip)
  127. print 'triangle'
  128.  
  129. def manipArrow(*arg):
  130. manip = cmds.ls(selection = True)
  131. oldManipShape = cmds.listRelatives(shapes=True)
  132. trgtTranslate = cmds.xform(query=True, translation=True, worldSpace=True, )
  133. trgtRotate = cmds.xform(query=True, rotation=True, worldSpace=True, )
  134. arrowManip = cmds.circle(nr=(0,1,0), degree = 1, sections = 7, )
  135. arrowShape = cmds.listRelatives(arrowManip, shapes=True)
  136. arrowTranform = cmds.listRelatives(arrowShape, parent=True)
  137. cmds.move(0, 0, -2, arrowTranform[0] + ".cv[0]" , arrowTranform[0] + ".cv[7]")
  138. cmds.move(1, 0, -1, arrowTranform[0] + ".cv[1]")
  139. cmds.move(-1, 0, -1, arrowTranform[0] + ".cv[6]")
  140. cmds.move(0.5, 0, -1, arrowTranform[0] + ".cv[2]")
  141. cmds.move(-0.5, 0, -1, arrowTranform[0] + ".cv[5]")
  142. cmds.move(0.5, 0, 1, arrowTranform[0] + ".cv[3]")
  143. cmds.move(-0.5, 0, 1, arrowTranform[0] + ".cv[4]")
  144. cmds.xform(arrowManip, translation=trgtTranslate, worldSpace=True, )
  145. cmds.xform(arrowManip, rotation=trgtRotate, )
  146. newManip = cmds.ls(sl=True)[0]
  147. newManipShape = cmds.listRelatives(shapes=True)
  148. cmds.select(newManipShape, manip )
  149. cmds.parent(relative=True, shape=True)
  150. cmds.delete(oldManipShape)
  151. cmds.rename(newManipShape, oldManipShape)
  152. cmds.delete(newManip)
  153. cmds.select(manip)
  154. print 'arrow'
  155.  
  156. def manipCross(*arg):
  157. manip = cmds.ls(selection = True)
  158. oldManipShape = cmds.listRelatives(shapes=True)
  159. trgtTranslate = cmds.xform(query=True, translation=True, worldSpace=True, )
  160. trgtRotate = cmds.xform(query=True, rotation=True, worldSpace=True, )
  161. arrowManip = cmds.circle(nr=(0,1,0), degree = 1, sections = 24, )
  162. arrowShape = cmds.listRelatives(arrowManip, shapes=True)
  163. arrowTranform = cmds.listRelatives(arrowShape, parent=True)
  164. cmds.move(0, 0, -2, arrowTranform[0] + ".cv[0]", arrowTranform[0] + ".cv[24]", )
  165. cmds.move(-0.6, 0, -1, arrowTranform[0] + ".cv[1]", )
  166. cmds.move(0.6, 0, -1, arrowTranform[0] + ".cv[23]", )
  167. cmds.move(-0.25, 0, -1, arrowTranform[0] + ".cv[2]", )
  168. cmds.move(0.25, 0, -1, arrowTranform[0] + ".cv[22]", )
  169. cmds.move(2, 0, 0, arrowTranform[0] + ".cv[18]", )
  170. cmds.move(1, 0, 0.6, arrowTranform[0] + ".cv[17]", )
  171. cmds.move(1, 0, -0.6, arrowTranform[0] + ".cv[19]", )
  172. cmds.move(1, 0, 0.25, arrowTranform[0] + ".cv[16]", )
  173. cmds.move(1, 0, -0.25, arrowTranform[0] + ".cv[20]", )
  174. cmds.move(0, 0, 2, arrowTranform[0] + ".cv[12]", )
  175. cmds.move(-0.6, 0, 1, arrowTranform[0] + ".cv[11]", )
  176. cmds.move(0.6, 0, 1, arrowTranform[0] + ".cv[13]", )
  177. cmds.move(-0.25, 0, 1, arrowTranform[0] + ".cv[10]", )
  178. cmds.move(0.25, 0, 1, arrowTranform[0] + ".cv[14]", )
  179. cmds.move(-2, 0, 0, arrowTranform[0] + ".cv[6]", )
  180. cmds.move(-1, 0, -0.6, arrowTranform[0] + ".cv[5]", )
  181. cmds.move(-1, 0, 0.6, arrowTranform[0] + ".cv[7]", )
  182. cmds.move(-1, 0, -0.25, arrowTranform[0] + ".cv[4]", )
  183. cmds.move(-1, 0, 0.25, arrowTranform[0] + ".cv[8]", )
  184. cmds.move(-0.25, 0, -0.25, arrowTranform[0] + ".cv[3]", )
  185. cmds.move(-0.25, 0, 0.25, arrowTranform[0] + ".cv[9]", )
  186. cmds.move(0.25, 0, 0.25, arrowTranform[0] + ".cv[15]", )
  187. cmds.move(0.25, 0, -0.25, arrowTranform[0] + ".cv[21]", )
  188. cmds.xform(arrowManip, translation=trgtTranslate, worldSpace=True, )
  189. cmds.xform(arrowManip, rotation=trgtRotate, )
  190. newManip = cmds.ls(sl=True)[0]
  191. newManipShape = cmds.listRelatives(shapes=True)
  192. cmds.select(newManipShape, manip )
  193. cmds.parent(relative=True, shape=True)
  194. cmds.delete(oldManipShape)
  195. cmds.rename(newManipShape, oldManipShape)
  196. cmds.delete(newManip)
  197. cmds.select(manip)
  198. print 'cross'
  199.  
  200. #Change manip's color:
  201.  
  202. def manipRed(*arg):
  203. manip = cmds.ls(sl=True)
  204. manipShp = cmds.listRelatives(manip, s = True)
  205. shpSlctd = len(manip)
  206. if shpSlctd ==0:
  207. popUpSlct()
  208. print ('Nothing Selected')
  209. else:
  210. for n in manipShp:
  211. cmds.setAttr(n + ".overrideEnabled", 1)
  212. cmds.setAttr(n + ".overrideColor", 13)
  213. print 'Roses Are Red...'
  214.  
  215. def manipBlue(*arg):
  216. manip = cmds.ls(sl=True)
  217. manipShp = cmds.listRelatives(manip, s = True)
  218. shpSlctd = len(manip)
  219. if shpSlctd ==0:
  220. popUpSlct()
  221. print ('Nothing Selected')
  222. else:
  223. for n in manipShp:
  224. cmds.setAttr(n + ".overrideEnabled", 1)
  225. cmds.setAttr(n + ".overrideColor", 6)
  226. print 'Violets Are Blue!'
  227.  
  228. def manipYellow(*arg):
  229. manip = cmds.ls(sl=True)
  230. manipShp = cmds.listRelatives(manip, s = True)
  231. shpSlctd = len(manip)
  232. if shpSlctd ==0:
  233. popUpSlct()
  234. print ('Nothing Selected')
  235. else:
  236. for n in manipShp:
  237. cmds.setAttr(n + ".overrideEnabled", 1)
  238. cmds.setAttr(n + ".overrideColor", 17)
  239. print 'Your controller is now yellow'
  240.  
  241. def manipGreen(*arg):
  242. manip = cmds.ls(sl=True)
  243. manipShp = cmds.listRelatives(manip, s = True)
  244. shpSlctd = len(manip)
  245. if shpSlctd ==0:
  246. popUpSlct()
  247. print ('Nothing Selected')
  248. else:
  249. for n in manipShp:
  250. cmds.setAttr(n + ".overrideEnabled", 1)
  251. cmds.setAttr(n + ".overrideColor", 14)
  252. print 'Your controller is now green'
  253.  
  254. def manipSkyBlue(*arg):
  255. manip = cmds.ls(sl=True)
  256. manipShp = cmds.listRelatives(manip, s = True)
  257. shpSlctd = len(manip)
  258. if shpSlctd ==0:
  259. popUpSlct()
  260. print ('Nothing Selected')
  261. else:
  262. for n in manipShp:
  263. cmds.setAttr(n + ".overrideEnabled", 1)
  264. cmds.setAttr(n + ".overrideColor", 18)
  265. print 'Your controller is now skyBlue'
  266.  
  267. #UI:
  268. window = cmds.window("toolBox_window", title="Tool Box Kawai", menuBar=True, width=250, height=100, backgroundColor=(0.75, 0.25, 0.5))
  269. cmds.menu(label='Options')
  270. cmds.menuItem(label='Turn Off Auxilliary power', command=('cmds.deleteUI(\"'+window+'\", window=True)'))
  271. cmds.columnLayout('columnMain', adjustableColumn=True, rowSpacing=5, )
  272.  
  273. cmds.separator(height=10, style='none', bgc=(0.7, 0.2, 0.5), )
  274.  
  275. cmds.button('manipBtn', label='Create Manip', command = manipCreation, bgc=(0.6, 0.2, 0.5), )
  276.  
  277. cmds.separator(height=10, style='none', bgc=(0.7, 0.2, 0.5), )
  278.  
  279. cmds.rowLayout('rowManipRename', numberOfColumns=3, )
  280. cmds.text(label='New Name :', height=30, width = 60, )
  281. nameChosen = cmds.textFieldGrp('newNameChosen', bgc=(0.1, 0.1, 0.1), width = 130, )
  282. cmds.button('renameBtn', label='Rename', command = renamer, width = 65, bgc=(0.6, 0.2, 0.5), )
  283. cmds.setParent( '..' )
  284.  
  285. cmds.separator(height=10, style='none', bgc=(0.7, 0.2, 0.5), )
  286.  
  287. #Change manip's shape UI:
  288. cmds.text(label='Change Manip\'s Shape', height=30 )
  289. cmds.rowLayout('rowManipShape', numberOfColumns=5, columnWidth5=(50, 50, 50, 50, 50), )
  290. cmds.iconTextButton('circle', style='iconAndTextVertical', label='Circle', width=50, image='', command = manipCircle, )
  291. cmds.iconTextButton('square', style='iconAndTextVertical', label='Square', width=50, image='', command = manipSquare, )
  292. cmds.iconTextButton('triangle', style='iconAndTextVertical', label='Triangle', width=50, image='', command = manipTriangle, )
  293. cmds.iconTextButton('arrow', style='iconAndTextVertical', label='Arrow', width=50, image='', command = manipArrow, )
  294. cmds.iconTextButton('cross', style='iconAndTextVertical', label='Cross', width=50, image='', command = manipCross, )
  295. cmds.setParent( '..' )
  296.  
  297. cmds.separator(height=10, style='none', bgc=(0.7, 0.2, 0.5), )
  298.  
  299. #Change manip's color UI:
  300. cmds.text(label='Change Manip\'s Color', height=30 )
  301. cmds.rowLayout('rowManipColor', numberOfColumns=5, columnWidth5=(50, 50, 50, 50, 50), )
  302. cmds.iconTextButton('red', style='iconAndTextVertical', label='Red', width=50, image='', command = manipRed, )
  303. cmds.iconTextButton('blue', style='iconAndTextVertical', label='Blue', width=50, image='', command = manipBlue, )
  304. cmds.iconTextButton('yellow', style='iconAndTextVertical', label='Yellow', width=50, image='', command = manipYellow, )
  305. cmds.iconTextButton('green', style='iconAndTextVertical', label='Green', width=50, image='', command = manipGreen, )
  306. cmds.iconTextButton('skyBlue', style='iconAndTextVertical', label='Sky Blue', width=50, image='', command = manipSkyBlue, )
  307. cmds.setParent( '..' )
  308. cmds.showWindow(window)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement