Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # curiousDonkey.py
- # Script that creates multiple 3D models and all the currently existing models will draw their attention to the newly created model
- import maya.cmds as cmds
- import functools
- import random
- donkeyAmount = 10
- #UI Section#
- def createUI ( pWindowName, pCreateCallback) :
- windowID = 'windowID'
- if cmds.window ( windowID, exists=True):
- cmds.deleteUI ( windowID )
- cmds.window ( windowID, title=pWindowName, sizeable = False, resizeToFitChildren=True)
- cmds.rowColumnLayout( numberOfColumns = 2, columnWidth = [(1,150), (2,100)], columnOffset=[ (1, 'right', 5) ])
- cmds.text(label='Amount of Donkeys:')
- dunkeyTotal = cmds.intField (value = donkeyAmount)
- cmds.separator (h=10, style = 'none')
- cmds.separator (h=10, style = 'none')
- cmds.button ( label='Create', command=functools.partial(pCreateCallback, dunkeyTotal))
- def cancelCallback(*pArgs):
- if cmds.window (windowID, exists= True):
- cmds.deleteUI(windowID)
- cmds.button(label ='Cancel', command=cancelCallback)
- cmds.showWindow()
- def createCallback ( pAmountOfDonkeys, *pArgs ):
- print 'Apply button pressed.'
- donkeyAmount = cmds.intField( pAmountOfDonkeys, query=True, value=True)
- print 'Donkey Amount: %s' % (donkeyAmount)
- main(donkeyAmount)
- createUI( 'Curious Donkeys', createCallback)
- #Functions#
- def lookAtTheNewGuy ( pDonkeyList ) :
- #print '%s' % (pDonkeyList)
- if (pDonkeyList > 1 ) :
- for i in range (0, (len(pDonkeyList) - 1)) :
- #print '%s should look at %s' % (pDonkeyList[i], pDonkeyList[i+1])
- cmds.aimConstraint( pDonkeyList[i+1], pDonkeyList[i], aimVector=[1, 0, 0], name=pDonkeyList[i] + '_aimConstraint_#')
- else :
- print "Not enough objects to look at"
- def createNewDuplicate (pTransformName, pSelectedObject) :
- currentDuplicateCopy = cmds.duplicate( pTransformName, name=pTransformName + '_#' )
- #print 'Creating new Dunkey: %s' % (currentDuplicateCopy)
- x = random.uniform (-10, 10)
- y = 0
- z = random.uniform (-10, 10)
- cmds.move( x,y,z, currentDuplicateCopy )
- xRot = 0
- yRot = random.uniform(0,360)
- zRot = 0
- cmds.rotate( xRot, yRot, zRot, currentDuplicateCopy)
- return currentDuplicateCopy
- #Main#
- def main(pDonkeyAmount) :
- random.seed( 1234 )
- selectedObject = cmds.ls(selection = True)
- transformName = selectedObject[0]
- if len(selectedObject) == 1:
- for i in range (0, pDonkeyAmount):
- selectedObject = createNewDuplicate(transformName, selectedObject)
- cmds.select(selectedObject, add = True)
- allDonkeys = cmds.ls(orderedSelection = True, type = 'transform')
- lookAtTheNewGuy(allDonkeys)
- cmds.hide (transformName)
- else :
- print 'ERROR: Please select only 1 start object'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement