Advertisement
Guest User

CuriousDonkeyV2

a guest
Jul 6th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.08 KB | None | 0 0
  1. # curiousDonkey.py
  2. # Script that creates multiple 3D models and all the currently existing models will draw their attention to the newly created model
  3.  
  4. import maya.cmds as cmds
  5. import functools
  6. import random
  7.  
  8. donkeyAmount = 10
  9.  
  10. #UI Section#
  11. def createUI ( pWindowName, pCreateCallback) :
  12.  
  13.     windowID = 'windowID'
  14.    
  15.     if cmds.window ( windowID, exists=True):
  16.        
  17.         cmds.deleteUI ( windowID )
  18.        
  19.     cmds.window ( windowID, title=pWindowName, sizeable = False, resizeToFitChildren=True)  
  20.    
  21.     cmds.rowColumnLayout( numberOfColumns = 2, columnWidth = [(1,150), (2,100)], columnOffset=[ (1, 'right', 5) ])
  22.    
  23.     cmds.text(label='Amount of Donkeys:')
  24.    
  25.     dunkeyTotal = cmds.intField (value = donkeyAmount)
  26.    
  27.     cmds.separator (h=10, style = 'none')
  28.     cmds.separator (h=10, style = 'none')
  29.    
  30.     cmds.button ( label='Create', command=functools.partial(pCreateCallback, dunkeyTotal))
  31.    
  32.     def cancelCallback(*pArgs):
  33.         if cmds.window (windowID, exists= True):
  34.             cmds.deleteUI(windowID)
  35.            
  36.     cmds.button(label ='Cancel', command=cancelCallback)
  37.    
  38.     cmds.showWindow()
  39.    
  40. def createCallback ( pAmountOfDonkeys, *pArgs ):
  41.    
  42.     print 'Apply button pressed.'
  43.    
  44.     donkeyAmount = cmds.intField( pAmountOfDonkeys, query=True, value=True)
  45.    
  46.     print 'Donkey Amount: %s' % (donkeyAmount)
  47.     main(donkeyAmount)
  48.    
  49. createUI( 'Curious Donkeys', createCallback)
  50.  
  51. #Functions#
  52.  
  53. def lookAtTheNewGuy ( pDonkeyList ) :
  54.  
  55.     #print '%s' % (pDonkeyList)
  56.  
  57.     if (pDonkeyList > 1 ) :
  58.    
  59.         for i in range (0, (len(pDonkeyList) - 1)) :
  60.            
  61.             #print '%s should look at %s' % (pDonkeyList[i], pDonkeyList[i+1])
  62.             cmds.aimConstraint( pDonkeyList[i+1], pDonkeyList[i], aimVector=[1, 0, 0], name=pDonkeyList[i] + '_aimConstraint_#')
  63.        
  64.     else :
  65.        
  66.         print "Not enough objects to look at"
  67.  
  68. def createNewDuplicate (pTransformName, pSelectedObject) :
  69.  
  70.     currentDuplicateCopy = cmds.duplicate( pTransformName, name=pTransformName + '_#' )
  71.    
  72.     #print 'Creating new Dunkey: %s' % (currentDuplicateCopy)
  73.    
  74.     x = random.uniform (-10, 10)
  75.     y = 0
  76.     z = random.uniform (-10, 10)
  77.    
  78.     cmds.move( x,y,z, currentDuplicateCopy )
  79.    
  80.     xRot = 0
  81.     yRot = random.uniform(0,360)
  82.     zRot = 0
  83.    
  84.     cmds.rotate( xRot, yRot, zRot, currentDuplicateCopy)
  85.  
  86.     return currentDuplicateCopy
  87.    
  88. #Main#
  89.  
  90. def main(pDonkeyAmount) :
  91.     random.seed( 1234 )
  92.    
  93.     selectedObject = cmds.ls(selection = True)
  94.     transformName = selectedObject[0]
  95.    
  96.     if len(selectedObject) == 1:
  97.        
  98.         for i in range (0, pDonkeyAmount):
  99.          
  100.             selectedObject = createNewDuplicate(transformName, selectedObject)
  101.            
  102.             cmds.select(selectedObject, add = True)
  103.             allDonkeys = cmds.ls(orderedSelection = True, type = 'transform')
  104.        
  105.         lookAtTheNewGuy(allDonkeys)
  106.         cmds.hide (transformName)
  107.     else :
  108.        
  109.         print 'ERROR: Please select only 1 start object'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement