Tasks/EnableGameModeOnSelectedCharacters_Z.py

Tasks/EnableGameModeOnSelectedCharacters_Z.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Topic: FBFindModelByLabelName, FBCharacter, FBMessageBox
7 #
8 
9 from pyfbsdk import *
10 
11 # List of bones on which we need to set the degrees of freedom.
12 lBonesName = ( 'LeftForeArm', 'RightForeArm', 'LeftLeg', 'RightLeg' )
13 
14 # List of characters that we have handled.
15 lAffectedCharacterList = []
16 
17 # Needed to get to the list of characters in the scene.
18 gSystem = FBSystem()
19 gScene = gSystem.Scene
20 
21 # Create a function to set GameMode on a character.
22 def SetGameModeOnSelectedCharacters(pCharacter, pState = True):
23 
24  print 'Setting game mode for character \'%s\'' % pCharacter.Name
25 
26  # List of character bones, on which we will set the DOF
27  lBones = []
28  global lBonesName
29  # Find the desired bones in the current character by prefixing
30  # the character name as the namespace.
31  for lBoneName in lBonesName:
32  lBone = FBFindModelByLabelName( '%s:%s' % ( pCharacter.Name, lBoneName ))
33  if lBone: lBones.append( lBone )
34 
35  # Check that we have indeed found all the bones.
36  if len( lBonesName ) == len( lBones ):
37 
38  # Then set the DOF for X and Y rotation.
39  for lBone in lBones:
40  lBone.PropertyList.Find( 'RotationActive' ).Data = pState
41  lBone.PropertyList.Find( 'RotationMinX' ).Data = pState
42  lBone.PropertyList.Find( 'RotationMinY' ).Data = pState
43  lBone.PropertyList.Find( 'RotationMaxX' ).Data = pState
44  lBone.PropertyList.Find( 'RotationMaxY' ).Data = pState
45 
46  # Add the current character to the list of modified characters.
47  lAffectedCharacterList.append( lCharacter.Name )
48 
49  else:
50  # If we have a mismatch in bone names, or if we are missing
51  # bones, we inform the user that no work was done.
52  FBMessageBox( 'Warning', 'Unable to set game mode for character \'%s\'' % lCharacter.Name, "Ok" )
53 
54 # Look at all the characters in the scene.
55 for lCharacter in gScene.Characters:
56 
57  # Then locate those that are selected.
58  if lCharacter.Selected:
59  SetGameModeOnSelectedCharacters(lCharacter)
60 
61 # Feedback to the user, to let him know which characters were modified,
62 # if any.
63 if len( lAffectedCharacterList ) == 0:
64  if FBApplication().CurrentCharacter !=None:
65  if FBMessageBox( 'Information', 'Could not set Game Mode. No character is selected. \n Do you want to enable Game Mode on the current Character?', 'Yes', 'No' )==1:
66  SetGameModeOnSelectedCharacters(FBApplication().CurrentCharacter)
67  else:
68  FBMessageBox( 'Information', 'Could not set game mode. No character were selected.', 'Ok' )
69 
70 
71 else:
72  FBMessageBox( 'Information', 'Set game mode for characters :%s' % lAffectedCharacterList, 'Ok' )
73