Samples/Character/SaveLoadCharacterMarkerSetMapping.py

Samples/Character/SaveLoadCharacterMarkerSetMapping.py
1 # Copyright 2013 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 # Script description:
7 # Simple script showing how in easy way store and review marker assignment
8 #
9 # Topic: FBCharacter FBCharacterMarkerSet
10 #
11 
12 from pyfbsdk import *
13 
14 def CharacterMapping(pSave, pFile = None, pCharacter = FBApplication().CurrentCharacter):
15  if pCharacter == None:
16  return
17 
18  if pFile == None:
19  pFile = "@%s_Mapping.txt" % pCharacter.Name
20 
21  lMarkerSet = pCharacter.GetCharacterMarkerSet(True)
22 
23  lConfigFile = FBConfigFile(pFile)
24  if pSave:
25  if lMarkerSet:
26  lConfigFile.ClearFile()
27  for lProp in lMarkerSet.PropertyList:
28  if lProp.Name.endswith('.Markers'):
29 
30  lConstraintType = lMarkerSet.PropertyList.Find(lProp.Name.replace('.Markers', '.Constraint'))
31  if lConstraintType != None:
32  lConfigFile.Set(lProp.Name, "Type", "%d" % lConstraintType.Data)
33  else:
34  continue
35 
36  for lSrcId in range(lProp.GetSrcCount()):
37  lConfigFile.Set(lProp.Name, "Marker%d" % lSrcId, lProp.GetSrc(lSrcId).LongName)
38  else:
39  if lMarkerSet:
40  lMarkerSet.FBDelete()
41 
42  pCharacter.CreateCharacterMarkerSet(True)
43  lMarkerSet = pCharacter.GetCharacterMarkerSet(True)
44 
46 
47  for lProp in lMarkerSet.PropertyList:
48  if lProp.Name.endswith('.Markers'):
49  lMarkerList = []
50  lMarkerIndex = 0
51  while True:
52  lMarkerName = lConfigFile.Get(lProp.Name, "Marker%d" % lMarkerIndex)
53  if lMarkerName:
54  lMarkerIndex += 1
55  lMarkerModel = FBFindModelByLabelName(lMarkerName)
56  if lMarkerModel:
57  lMarkerList.append(lMarkerModel)
58  else:
59  break
60 
61  lProp.BeginChange()
62  lProp.DisconnectAllSrc()
63 
64  for lMarker in lMarkerList:
65  lProp.ConnectSrc(lMarker)
66 
67  lProp.EndChange()
68 
69  lConstraintType = lMarkerSet.PropertyList.Find(lProp.Name.replace('.Markers', '.Constraint'))
70  if lConstraintType != None:
71  lType = lConfigFile.Get(lProp.Name, "Type")
72  if lType:
73  lConstraintType.Data = int(lType)
74 
76 
77 def LoadMapping(pFile = None, pCharacter = FBApplication().CurrentCharacter):
78  CharacterMapping(False,pFile,pCharacter)
79 
80 def SaveMapping(pFile = None, pCharacter = FBApplication().CurrentCharacter):
81  CharacterMapping(True,pFile,pCharacter)
82 
83 # you have to first store mapping to be able to retrieve it.
84 SaveMapping()
85 # after storing, you are able to retrieve marker assignment
86 #LoadMapping()