Hey TheBeaver,
If you want to set your start and end frames. These will help:
def get_take_start_and_endframes(fcurve) -> tuple:
"""
Description: Method will return a take start and end frame numbers in the form of a tuple int!
Args: FBFCurve, The object's fcurve.
Return: (start, end) tuple int values or None if no keys are present.
"""
last_key_index = len(fcurve.Keys)-1 # -1 is due to frame will starts at 0
if last_key_index > 0:
start_key = fcurve.Keys[0]
end_key = fcurve.Keys[last_key_index]
start_frame = start_key.Time.GetFrame()
end_frame = end_key.Time.GetFrame()
print("Start frame: {0} and End frame {1}".format(start_frame, end_frame))
return (start_frame, end_frame)
else:
curve_name = fcurve.Name
# print(f"No keys found for {curve_name}")
print("Start frame: 0 and End frame 0")
return (0, 0)
def set_take_start_and_endframes(start_frame: int, end_frame: int, fcurve) -> None:
"""
Description: Sets start and end frames for a single take!
Args:
fcurve = FBFCurve
start_frame = int,
end_frame = int,
"""
FBPlayerControl().LoopStart = FBTime(0,0,0,start_frame)
FBPlayerControl().LoopStop = FBTime(0,0,0,end_frame)
Here is the export. It wont work because it is using my classes (mainly for building my export path). You can pick out the useful bits of code to use.
def export_takes(all_scene_takes: list):
"""
Description: Exports takes. This feature includes set fbx settings!
Note: FBX settings includes all scene content!
Param: all_scene_takes, a list of FBTakes.
"""
#Define lSystem
lSystem = FBSystem()
app = FBApplication()
# Create an FBFbxOptions object initialized to load data.
fbx_options = FBFbxOptions(False) # True if load/merge fbx file options and False for saving files!
# Below, Appends all the data in the file, which are appended
# into the current scene. The second parameter (if False) of SetAll() ignores
# any animation data contained in the file.
fbx_options.SetAll(FBElementAction.kFBElementActionSave, True)
fbx_options.FileFormatAndVersion = FBFileFormatAndVersion.kFBFBX2014_2015 # FBX save version 2014_2015
fbx_options.EmbedMedia = False # Dont save media files
print("\nExporting the following takes to Source:\n")
# Iterate through each take to export!
for take in lSystem.Scene.Takes:
for index in range( fbx_options.GetTakeCount( ) ):
if fbx_options.GetTakeName( index ) == take.Name:
fbx_options.SetTakeSelect( index, True )
else:
fbx_options.SetTakeSelect( index, False )
class_savepath = util.MiscUtils()
take_source_path = class_savepath.get_savepath_argument(take)
#If take SavePath property exists then do below!
# Note: SavePath argument has the take merge source path location to save when exporting!
if take_source_path:
#Merge all object in the scene to the BaseAnimation layer and delete the empty layers
FBSystem().CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)
take_name = take.Name
take_filepath = f"{take_source_path}/{take_name}.fbx"
# Do this to export take!
if take_filepath:
app.FileSave(take_filepath, fbx_options)
print(f"Exported: {take_filepath}")
# Do this when export has failed!
else:
# The return will be none due to failer to export! This will cancel the for loop and the export.
print(f"Take failed to export! Take name: {take_filepath}")
return None
return True # Returning True will confirm export was successful
type or paste code here
I hope this helps! 