Write Take info To Text File

In one of my previous posts a user left a comment asking “How can I print Take information out to a .txt file”. I figured that was as good as any topic to cover so here it is. 🙂

The script below will look at the open Motionbuilder scene’s name and file path – using that information it will create a new ‘.txt’ file and write some information.

from pyfbsdk import *

def WriteTakeInfo():
    ##Find The Scene's File Name And Use It To Create A .txt File
    mytextFile=FBApplication().FBXFileName[:-4]+"-TakeInfo.txt"
    
    ##Create And Open The New .txt File So That It May Be Wrote To
    textFile=open(mytextFile,"w")
   
    ##Create A List 
    sceneTakes=[]
    ##Go Through All Takes Within The Open Scene
    for myTake in FBSystem().Scene.Takes:
        ##For Each Take Create A Dictionary
        ##Store Take Name, Frame Count, Length, Start Time and Stop Time
        takeInfo={
        "Name":myTake.Name,
        "Frames":myTake.LocalTimeSpan.GetDuration().GetFrame(),
        "Seconds":myTake.LocalTimeSpan.GetDuration().GetSecondDouble(),
        "StartFrame":myTake.LocalTimeSpan.GetStart().GetFrame(),
        "EndFrame":myTake.LocalTimeSpan.GetStop().GetFrame()
        }
        ##Store The Dictionary Into Our List
        sceneTakes.extend([takeInfo])
        
    ##Go Through Each Dictionary In Our List And Write The Info To Our .txt File    
    for dict in sceneTakes:
        textFile.write("Take Name:" % dict["Name"])
        textFile.write('\n')
        textFile.write("Number of Frames:" % dict["Frames"])
        textFile.write('\n')
        textFile.write("Length of Time in Seconds:" % dict["Seconds"])
        textFile.write('\n')
        textFile.write("Start Frame:" % dict["StartFrame"])
        textFile.write('\n')
        textFile.write("End Frame:" % dict["EndFrame"])
        textFile.write('\n')
        textFile.write("-----------------------------------------------------------------")
        textFile.write('\n')
    
    ##Close The .txt File
    textFile.close()

I am sure my string formating could be alot better, but this gets the job done.

I hope this helps.

2 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.