Python: Merge fbx: Change take name during merge. Simulate "As Take" option in Merge Options UI

Python: Merge fbx: Change take name during merge. Simulate "As Take" option in Merge Options UI

Jerry.Gilland
Explorer Explorer
2,033 Views
2 Replies
Message 1 of 3

Python: Merge fbx: Change take name during merge. Simulate "As Take" option in Merge Options UI

Jerry.Gilland
Explorer
Explorer

Through Python, I want to simulate what is done through the "File > Merge > Merge Options > As Take" setting that allows you to set the take name during merging.

 

I've not found the right setting or command to do this.  I'm currently using FileMerge with updated FBFbxOptions with no success so far.

 

Thank you!

0 Likes
Accepted solutions (1)
2,034 Views
2 Replies
Replies (2)
Message 2 of 3

Mocappy
Advocate
Advocate
Accepted solution

Hi,

 

Couple of things you will need....

  1. SetTakeDestinationName - to change the take name using "As Take..." - I know, I though it would be "SetTakeName", but this changes the name in the "Takes" column?!?!
  2. OnFileMerge - This allows you to perform operations in the Merge Options UI, basically pauses the Merge operation while you change the setting in the window
  3. Index of the take name you want to change. If there's only one take in the file, use 0 (zero)

So something like this should do what you want...providing you only have one take in the file and want to change that take name.

 

from pyfbsdk import *

def merge_file(file_path, as_take_name):
    def _set_take_destination_name(pCaller, pEvent):
        ''' 
        pCaller: In this example, it will be the FBApplication object.
        pEvent:  An instance of the FBEvent triggered.
        '''
        # Change Take Destination Name using index
        merge_options.SetTakeDestinationName(0, as_take_name)
        # Remove the callback function when file merge is complete.
        pCaller.OnFileMerge.RemoveAll()

    merge_options = FBFbxOptions(True)
    # Turn off Merge File window
    merge_options.ShowOptionsDialog = False
    # Merge all Elements. Merge All Animation
    merge_options.SetAll(FBElementAction.kFBElementActionMerge, True)
    ## --------------------------- Open File ---------------------------
    # Create callback function on the OnFileMerge event.
    FBApplication().OnFileMerge.Add(_set_take_destination_name)
    # Merge File
    FBApplication().FileMerge(file_path, False, merge_options)

merge_file_path = FULL_PATH_TO_FILE
merge_file(merge_file_path, "NEW TAKE NAME")

 

Hope this helps,

 

Message 3 of 3

Jerry.Gilland
Explorer
Explorer

Thank you so much!!  Yes, I thought SetTakeName should be it as well 🙂