Write Take info To Text File
Posted On March 23, 2021
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.
3 Comments
awesome, but but when I start script, .txt file is not create. Not existing. No error.
Sorry for the late reply, things are very busy.
I forgot to add “from pyfbsdk import *” as the first line, if you are using a fresh boot of Mobu and did not run any other scripts you would have issues (and it’s just bad form to ommit it from the first line).
I hope this helps you with the script.
Man, you made a great work! I wanna ask you that is possible to create a “Snapshot” tool for mesh in Mobu like we have in maya ?