MotionBuilder Python My Fav Story Functions
Posted On July 17, 2018
After posting “MotionBuilder Python Library aka. My Fav Functions” I thought I would follow up with some breakdown on manipulating Story Tracks, Clips and Folders with MotionBuilder’s Python modules. I briefly covered this a while ago here but that was really just an example of how to put characters into the Story under a folder – which comes in handy, but no real break down on what it is. Here are some of my favorite functions and some examples on how to manipulate Story using Python.
import pyfbsdk as fb import pyfbsdk_additions as fba ''' Acessing Story Tracks And Clips Below Are 3 Funcitons That Will Help Expose Any Story Track Or Story Clip That You Have Selected Within Your Stroy Window ''' ##Show Selected Tracks Modules def ShowSelTrackAtt(): for track in fb.FBStory().RootFolder.Tracks: if track.Selected == True: print track.Type, track.Name, "\n" print dir(track) ##Show Selected Clips Modules def ShowSelClipAtt(): for track in fb.FBStory().RootFolder.Tracks: for clip in track.Clips: if clip.Selected == True: print track.Name, clip.Name, "Att: " + "\n" print dir(clip) ##Show Selected Clips Properties def ShowSelClipProperties(): for track in fb.FBStory().RootFolder.Tracks: for clip in track.Clips: if clip.Selected == True: print track.Name, clip.Name, "Properties: " + "\n" for i in dir(clip.PropertyList.FBFindPropertiesByName): print i ''' These Two Function GetSelModels() And GetSelCameras() Will Be Used To Help Demonstrate The Creation Of Animation Tracks And Camera Tracks ''' ##Returns A List Of All Selected Models def GetSelModels(): lSelModels = [] modelList = fb.FBModelList() fb.FBGetSelectedModels (modelList, None, True) for model in modelList: if model.Selected == True: lSelModels.extend([model]) else: pass return lSelModels ##Returns A List Of All Selected Cameras def GetSelCameras(): for camera in fb.FBSystem().Scene.Cameras: if camera.Selected == True: return camera else: pass ''' Dealing With All The Different Types Of Story Tracks ''' ##List All The Different Types Of Story Clips def ListStoryClipTypes(): for i in dir(fb.FBStoryTrackType): if "kFBStoryTrack" in i: print i else: pass ''' How to Create A Track For Each Different Story Track Type ''' ##How To Create Animation Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAnimation) ##How To Create Audio Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAudio) ##How To Create Camera Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCamera) ##How To Create Character Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter) ##How To Create Command Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCommand) ##How To Create Constraint Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackConstraint) ##How To Create Shot Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackShot) ##How To Create Video Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackVideo) ''' To Name A Story Track You Can Do It At Creation With The Label Attribute ''' ##How To Create And Name An Animation Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAnimation).Label = "My Aniamtion Track" ##How To Create And Name An Audio Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAudio).Label = "My Audio Track" ##How To Create And Name An Camera Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCamera).Label = "My Camera Track" ##How To Create And Name An Character Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter).Label = "My Character Track" ##How To Create And Name An Command Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCommand).Label = "My Command Track" ##How To Create And Name An Constraint Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackConstraint).Label = "My Constraint Track" ##How To Create And Name An Shot Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackShot).Label = "My Shot Track" ##How To Create And Name An Video Track fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackVideo).Label = "My Video Track" ''' To Create A Track And Assign A Source We Need To Use The .Detail.append() Attribute ''' ##Create A Character Animation Track Within The Root Folder Of Story lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter, fb.FBStory().RootFolder) lTrack.Details.append(fb.FBApplication().CurrentCharacter) ##Create An Animation Track And Assign An Object selObj = GetSelModels() lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAnimation, fb.FBStory().RootFolder) for i in selObj: lTrack.Details.append(i) ##Create A Camera Track Adn Assign A Camera selCams = GetSelCameras() lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCamera, fb.FBStory().RootFolder) lTrack.Details.append(selCams) ''' Creating A Track With An Assigned Source And Data Copied To It We Will Be Using .CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake ) ''' ##Create A Character Animatin Track Within The Root Folder Of Story lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter, fb.FBStory().RootFolder) ##Assign Our Currently Selected Character To Be Our Track's Character lTrack.Details.append(fb.FBApplication().CurrentCharacter) ##Our Data Will Be The Currnet Take lTrack.CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake ) ##Create An Animation Track And Assign An Object selObj = GetSelModels() lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackAnimation, fb.FBStory().RootFolder) for i in selObj: lTrack.Details.append(i) ##Our Data Will Be The Currnet Take lTrack.CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake ) ##Create A Camera Track Adn Assign A Camera selCams = GetSelCameras() lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCamera, fb.FBStory().RootFolder) lTrack.Details.append(selCams) ##Our Data Will Be The Currnet Take lTrack.CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake ) ''' Move Clips Along The Time Line Using .Start = fb.FBTime() ''' ##This Will Move All Selected Clips To Start At Frame 150 for track in fb.FBStory().RootFolder.Tracks: for clip in track.Clips: if clip.Selected == True: clip.Start = fb.FBTime(0,0,0,150) ''' Speeding Up The Clip ''' ##This Will Speed Up All Selected Clips To Be 2x The Original Speed for track in fb.FBStory().RootFolder.Tracks: for clip in track.Clips: if clip.Selected == True: clip.Speed = 2 ''' Working With Tracks And Folders Within Story ''' ##Creating A Story Folder ie. CreatStoryFolder("My Story Folder") Will Create A Folder Within The Story Called "My Story Folder" def CreatStoryFolder(foldername): lFolder = fb.FBStoryFolder() lFolder.Label = foldername ''' Putting It All Together: ''' ##Create A Folder Labled As The Take Name And Create A Character Track With The Lable Of The Character def SendToStory(): ##Folder Set Up lfoldername = fb.FBSystem().CurrentTake.Name lFolder = fb.FBStoryFolder() lFolder.Label = lfoldername ##Character Track lCharTrack = fb.FBStoryTrack(FBStoryTrackType.kFBStoryTrackCharacter, lFolder) # assign our CurrentCharacter to the track lCharTrack.Details.append(FBApplication().CurrentCharacter) lCharTrack.Label = FBApplication().CurrentCharacter.LongName # Insert current take in the newly created track lCharTrack.CopyTakeIntoTrack( fb.FBSystem().CurrentTake.LocalTimeSpan, fb.FBSystem().CurrentTake )
So now that we have some of my favorite functions exposed, let’s head over here to see them all working together. 🙂
As always I hope this helps.