{"id":794,"date":"2021-01-07T10:34:14","date_gmt":"2021-01-07T15:34:14","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=794"},"modified":"2021-01-07T10:34:23","modified_gmt":"2021-01-07T15:34:23","slug":"using-motionbuilder-python-to-offset-all-animations-within-a-scene","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-offset-all-animations-within-a-scene\/","title":{"rendered":"Using MotionBuilder Python To Offset All Animations Within A Scene"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"797\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-offset-all-animations-within-a-scene\/offset-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=960%2C540\" data-orig-size=\"960,540\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=300%2C169\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=678%2C381\" decoding=\"async\" loading=\"lazy\" width=\"678\" height=\"381\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?resize=678%2C381\" alt=\"\" class=\"wp-image-797\" srcset=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?w=960 960w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?resize=300%2C169 300w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?resize=768%2C432 768w\" sizes=\"(max-width: 678px) 100vw, 678px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>Here is a quick script that will allow you to shift\/offset all animation keys within a scene. Previously I would do this via story mode or use another technique that would skip over props and\/or constraints. This script should shift everything within the scene that is animated.<\/p>\n\n\n\n<p>The script is not good for things like offsetting one character within a scene while leaving other objects\/characters alone &#8211; this will move everything within the scene.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pyfbsdk import *\n\n##Get All Animation Nodes Within The Scene\ndef getAnimatedNodes():\n    animNodes = &#x5B;]\n    for i in FBSystem().Scene.Components:\n        for property in i.PropertyList:\n            try:\n                if property.IsAnimated() == True:\n                    animNodes.extend( &#x5B;property.GetAnimationNode()] )\n            except: pass\n    if len(animNodes) != 0:\n        return animNodes\n\n##OffSet A List Of Animation Node By A Desired Number        \ndef OffSetAnimation( pAnimated = list, pFrameOffSet = int ):\n    for i in pAnimated:\n        ##Deal With Properties That Have Single FCurve (IK Blends, IK Pull, Ref. Properties, Etc.)\n        try:\n            i.FCurve.KeyOffset( FBTime( 0, 0, 0, pFrameOffSet ) )\n        except: pass\n        ##Deal With Properties That Have Multiple Nodes (X, Y, Z Axis)\n        try:\n            for n in range( len(i.Nodes) ):\n                if i.Nodes&#x5B; n ].KeyCount != 0:\n                    i.Nodes&#x5B; n ].FCurve.KeyOffset( FBTime( 0, 0, 0, pFrameOffSet ) )         \n        except: pass\n\n##Offset All Animation On A Take So That The Animation Starts At Frame Zero        \ndef StartTakeAnimAtFrameZero():\n    ##Set Scene To 30FPS And Time Line To Show Frames\n    FBPlayerControl().SetTransportFps(FBTimeMode.kFBTimeMode30Frames)\n    FBPlayerControl().TransportTimeFormat = FBTransportTimeFormat.kFBTimeFormatFrame\n    ##Get The Takes Original Info\n    pTakeStart = FBSystem().CurrentTake.LocalTimeSpan.GetStart().GetFrame()\n    pTakeLength = FBSystem().CurrentTake.LocalTimeSpan.GetDuration().GetFrame()\n    ##Offset Animation\n    animatedNodes = getAnimatedNodes()\n    OffSetAnimation( animatedNodes, -pTakeStart )\n    ##Set Time Line To Reflect The New OffSet\n    FBSystem().CurrentTake.LocalTimeSpan = FBTimeSpan( FBTime(0, 0, 0, 0, 0), FBTime(0, 0, 0, pTakeLength, 0) )\n    FBPlayerControl().Goto( FBTime(0, 0, 0, 0, 0) )\n\n##Go Through Every Take Within A Scene And Offset The Animation So That They Start On Frame Zero\ndef OffsetAllTakesToFrameZero():\n    ##Store Current Take\n    ogTake = FBSystem().CurrentTake\n    ##Go Throuhg Every Take Within The Scene And Offset Keys To Start On Frame Zero\n    for take in FBSystem().Scene.Takes:\n        FBSystem().CurrentTake = take\n        StartTakeAnimAtFrameZero()\n    ##Return To The Take We Were On When We Started The Process    \n    FBSystem().CurrentTake = ogTake\n\n'''\nHow To Use The Functions\n'''\n##Example of offsetting an animation by a specific frame amount\n##Get the animated nodes within the scene\nmyAnimatedNodes = getAnimatedNodes()\n##Offset the animation nodes to start 100 frames later in the time line\nOffSetAnimation( myAnimatedNodes , 100 )\n##Offset the animation nodes to start 300 frames earlier in the time line\nOffSetAnimation( myAnimatedNodes , -300 )\n\n##Offset all keys to start at frame zero\nStartTakeAnimAtFrameZero()\n\n##Offset all takes within the scene so that keys start at frame zero\nOffsetAllTakesToFrameZero()\n\n\n<\/pre><\/div>\n\n\n<p>I hope this helps.<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Here is a quick script that will allow you to shift\/offset all animation keys within a scene. Previously I would do this via story mode or use another technique that would skip over props and\/or constraints. This script should shift everything within the scene that is animated. The script is not good for things like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":797,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"I finally created a new post to my #MotionBuilder #Python blog. This post shows how to offset all animated keys within a scene quickly. Useful for getting mocap to start on frame zero.\n\nI hope this helps. :) ","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4],"tags":[12,13],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=960%2C540","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-cO","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":127,"url":"http:\/\/www.vicdebaie.com\/blog\/running-a-python-script-on-all-takes\/","url_meta":{"origin":794,"position":0},"title":"Running A Python Script On All Takes.\u00a0\ufeff","author":"admin","date":"February 18, 2017","format":false,"excerpt":"Being able to run a Python script on all takes within a MotionBuilder scene is a powerful time saver. Below I'm going to show how I learned to create a layer on every take within a MotionBuilder scene using Python. We are going to\u00a0use Python to create an Animation Layer\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":274,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-import-motionbuilder-characters-into-story\/","url_meta":{"origin":794,"position":1},"title":"Using Python to import MotionBuilder Characters into story.\u00a0","author":"admin","date":"April 6, 2017","format":false,"excerpt":"\u00a0 MotionBuilder comes with a great script that will place your selected character into a Character Track within the Story, I wanted to write one that would put all of the scene's Characters into the story. Once again I will use the \"Mia_Rigged.fbx\" file to test my script. I created\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/MobuPython_StoryScript.jpg?fit=1011%2C224&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/MobuPython_StoryScript.jpg?fit=1011%2C224&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/MobuPython_StoryScript.jpg?fit=1011%2C224&resize=700%2C400 2x"},"classes":[]},{"id":336,"url":"http:\/\/www.vicdebaie.com\/blog\/how-to-use-functions-with-motionbuilder-python\/","url_meta":{"origin":794,"position":2},"title":"How to use functions with MotionBuilder Python","author":"admin","date":"April 25, 2017","format":false,"excerpt":"Using functions will save you from re-writing and maintaining many of the same lines of code over and over. What is a Python Function? \"A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/c2c827b3a6ea16d024b6875b5610651c-e1493127532666.gif?fit=251%2C300&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":711,"url":"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-cast-real-time-shadows\/","url_meta":{"origin":794,"position":3},"title":"Using MotionBuilder Python To Cast Real-Time Shadows","author":"admin","date":"September 18, 2019","format":false,"excerpt":"Using Python To Quickly Add A Real Time Shadow To Your MotionBuilder Scene.","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/09\/ShadowCube.png?fit=1157%2C526&resize=1050%2C600 3x"},"classes":[]},{"id":83,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/","url_meta":{"origin":794,"position":4},"title":"Using Python to Create a layer on the Current Selected Take in MotionBuilder.\u00a0","author":"admin","date":"February 9, 2017","format":false,"excerpt":"In MotionBuilder using animation layers are great for edits, blending, additives and in general adding quality passes to your animations. So below I'm going to demo how I learned to add layers\u00a0using Python. To create an Animation Layer on the Current Take script: Now let's setup a Python Script to\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":528,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-clean-character-from-scene-with-fbdelete\/","url_meta":{"origin":794,"position":5},"title":"MotionBuilder Python Clean Character From Scene with FBDelete()","author":"admin","date":"April 23, 2018","format":false,"excerpt":"This is a script that came about while researching and writing examples for my previous post on FBDelete(). This bit of script will go through a number of constructors within the FBSystem() class. Here is a list of the classes in which our list will go through: fb.FBSystem().Scene.Constraints fb.FBSystem().Scene.Handles fb.FBSystem().Scene.UserObjects\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"http:\/\/www.vicdebaie.com\/blog\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/04\/delete.jpg?fit=768%2C512&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/04\/delete.jpg?fit=768%2C512&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/04\/delete.jpg?fit=768%2C512&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/794"}],"collection":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":2,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"predecessor-version":[{"id":798,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions\/798"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/797"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}