from pyfbsdk import *
from Qt.QtCore import *
from Qt.QtGui import *
from Qt.QtWidgets import *
from pyfbsdk_additions import *
tool = FBCreateUniqueTool("TakeReNamer_v1.0")
tool.StartSizeX = 270
tool.StartSizeY = 400
ShowTool(tool)
window = ''
for i in QApplication.topLevelWidgets():
if i.windowTitle() == 'TakeReNamer_v1.0':
window = i
if window:
cen_layout = QVBoxLayout(window)
window.setLayout(cen_layout)
layout = QVBoxLayout(window)
cen_layout.addLayout(layout)
t = RickMainWindow()
layout.addWidget(t)
t.show()
def export_take(takes):
selectedModels = []
for comp in FBSystem().Scene.Components:
if comp.Selected:
selectedModels.append(comp)
lOptions = FBPlotOptions()
lOptions.ConstantKeyReducerKeepOneKey = False
lOptions.PlotAllTakes = False
lOptions.PlotOnFrame = True
lOptions.PreciseTimeDiscontinuities = False
lOptions.PlotLockedProperties = False
lOptions.RotationFilterToApply = FBRotationFilter.kFBRotationFilterUnroll
lOptions.PlotTranslationOnRootOnly = False
lOptions.UseConstantKeyReducer = False
for lTake in takes:
for comp in FBSystem().Scene.Components:
comp.Selected = False
char = FBApplication().CurrentCharacter
char.PlotAnimation(
FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton, lOptions)
SelectSkeletonHierarchy(GetCharSkeletonRoot(char))
Publish(lTake)
char.ActiveInput = True
del char
for comp in selectedModels:
comp.Selected = True
del (selectedModels, comp, lOptions, lTake)
def SelectSkeletonHierarchy(top_model):
for childModel in top_model.Children:
SelectSkeletonHierarchy(childModel)
if FBModel.FbxGetObjectSubType(
top_model) == 'FBModelSkeleton' or FBModel.FbxGetObjectSubType(
top_model) == 'FBModelRoot':
top_model.Selected = True
def GetCharSkeletonRoot(char):
ls_characters = []
ls_char_roots = FBComponentList()
FBFindObjectsByName('root', ls_char_roots, False, True)
char_root = char.GetModel(FBBodyNodeId.kFBHipsNodeId).Parent
if char_root in ls_char_roots:
currChar_namespace = ''
if ":" in char_root.LongName:
currChar_namespace = char_root.LongName.rsplit(':', 2)[0]
if currChar_namespace != '':
currChar_namespace = currChar_namespace + ':'
ls_characters.append([char, char_root, currChar_namespace])
skelRoot = ls_characters[0][1]
del (currChar_namespace)
else:
skelRoot = char_root
del (ls_characters, ls_char_roots, char_root)
return skelRoot
def Publish(take, char):
FBSystem().CurrentTake = take
lFileOptions = FBFbxOptions(False)
lFileOptions.SaveSelectedModelsOnly = True
lFileOptions.ShowFileDialog = False
lFileOptions.ShowOptionsDialog = False
lFileOptions.UpdateRecentFiles = False
for index in range(lFileOptions.GetTakeCount()):
if lFileOptions.GetTakeName(index) == take.Name:
lFileOptions.SetTakeSelect(index, True)
else:
lFileOptions.SetTakeSelect(index, False)
file_split = os.path.split(FBApplication().FBXFileName)
base_path = file_split[0] + '\\export'
if not os.path.exists(base_path):
os.makedirs(base_path)
base_file = base_path + '\\' + take.Name
FBApplication().FileSave(base_file, lFileOptions)
for comp in FBSystem().Scene.Components:
comp.Selected = False
del (lFileOptions, take, file_split, base_path, base_file, comp)