############################################################################# # crystalball.py Version 1.1 by Andrew Osiow Copyright 2009 # # fun script to emulate a fortune teller in Maya # User can type in a question and get back one of a few standard answers # # Uses sytem to generate random number - current set for Windows only # # The interface consists of a dummy question area and random generated answer # ############################################################################# import maya.cmds as cmds import datetime import math import random def crystalball(): # opens a Crystal Ball/Fortune Telling interface # delete any old Crystalball window preferences if cmds.windowPref( 'crystalBallWindow', exists=True ): cmds.windowPref( 'crystalBallWindow', remove=True ) # delete any old Crystalball window structures if cmds.window( 'crystalBallWindow', exists=True ): cmds.deleteUI( 'crystalBallWindow', window=True ) # create a window structure felixWin = cmds.window( 'crystalBallWindow', title='CrystalBall v1.0', iconName='CrystalBall', rtf=1, s=0) # create Crystal Ball layout crystalBallForm = cmds.formLayout( 'crystalBallForm', numberOfDivisions=100, h=110, w=200) # make Gadgets cmds.text('cbQuestionLabelText',label='State Your Question.') cmds.text('cbAnswerLabelText',label='Response:') cmds.textField('cbQuestionGadet', text='Type a \"Yes or No\" Question', width=190) cmds.textField('cbAnswerGadet', text='', width=116, ed=False) cmds.button('crystalBallTellMeButton', width=90, height=26, label='Tell Me!', align='center', command=makeCrystalBallAnswer) cmds.button('closeCrytalBallButton', width=90, height=26, label='I\'m Done.', align='center', command="import maya.cmds as cmds\ncmds.deleteUI( 'crystalBallWindow')") # Layout Gadgets cmds.formLayout( crystalBallForm, edit=True, attachForm=[ ('cbQuestionLabelText', 'left', 20 ), ('cbQuestionLabelText', 'top', 6 ), ('cbQuestionGadet', 'left', 5 ), ('cbQuestionGadet', 'top', 26 ), ('cbAnswerLabelText', 'left', 20 ), ('cbAnswerLabelText', 'top', 54 ), ('cbAnswerGadet', 'top', 52 ), ('crystalBallTellMeButton', 'left', 4 ), ('crystalBallTellMeButton', 'top', 80 ), ('closeCrytalBallButton', 'right', 4 ), ('closeCrytalBallButton', 'top', 80 ) ], attachControl=[ ('cbAnswerGadet', 'left', 5, 'cbAnswerLabelText' )]) # display CrystalBall Window cmds.showWindow ('crystalBallWindow') # end CrystalBall definition def makeCrystalBallAnswer(*args): # Generate a Random Answer # answer List answerList = ( 'Definitely', 'Unlikely', 'Not Sure. Ask again', 'Probably', 'Yes', 'No' ) # grab the current question theQuestion = cmds.textField('cbQuestionGadet', q=True, text=True ) # calculate length theLength = len(theQuestion); # get the current Time currentTime = datetime.datetime.now() print currentTime print currentTime.microsecond hundredthSec = math.floor(currentTime.microsecond * 0.0001) # Generate a Random Response random.seed( theLength * hundredthSec ) randomNumber = random.randrange (1,7) # Set the answer cmds.textField('cbAnswerGadet', e=True, text = answerList[randomNumber-1]) # end makeCrystalBallAnswer definition