{"id":127,"date":"2017-02-18T09:00:08","date_gmt":"2017-02-18T14:00:08","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=127"},"modified":"2019-04-29T12:27:36","modified_gmt":"2019-04-29T16:27:36","slug":"running-a-python-script-on-all-takes","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/running-a-python-script-on-all-takes\/","title":{"rendered":"Running A Python Script On All Takes.\u00a0\ufeff"},"content":{"rendered":"<p><img data-attachment-id=\"129\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/running-a-python-script-on-all-takes\/img_3936\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3936.jpg?fit=169%2C99\" data-orig-size=\"169,99\" 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\/2017\/02\/IMG_3936.jpg?fit=169%2C99\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3936.jpg?fit=169%2C99\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-129\" title=\"\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3936.jpg?resize=169%2C99\" alt=\"\" width=\"169\" height=\"99\"  data-recalc-dims=\"1\"><\/p>\n<p>Being able to run a Python script on all takes within a MotionBuilder scene is a powerful time saver.<\/p>\n<p>Below I&#8217;m going to show how I learned to create a layer on every take within a MotionBuilder scene using Python.<\/p>\n<p>We are going to&nbsp;use Python to create an Animation Layer on all takes within our scene:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pyfbsdk import *\n\n#Define lSystem\nlSystem = FBSystem()\n\n# On all Takes within the Scence\nfor take in FBSystem().Scene.Takes:\n#Create a new layer\nlSystem.CurrentTake.CreateNewLayer()\n#Find how many layers are now in the take\nlCount = lSystem.CurrentTake.GetLayerCount()\n\n#set the new layer (the top layer)as the current one (Keys will be added to that layer)\nlSystem.CurrentTake.SetCurrentLayer(lCount-1)\n<\/pre>\n<p>The above code works, however there is an issue with how user friendly it is.&nbsp;We are always one&nbsp;the last take in our scene once the script is finished &#8211; LET&#8217;S FIX IT&nbsp;! \ud83d\ude42<\/p>\n<p>Using pyfbsdk to create layers is great but the fun is merging all layers on all takes through a Python script. I run a script similar to the one below when I am doing my final clean up within my MotionBuilder scene. Once the script has finished running you will be positioned back onto the take in which you were on before&nbsp;you executed the script &#8211; this is great if you are dealing with a lot of takes.<\/p>\n<p>A word of <em><strong>warning<\/strong>&nbsp;<\/em>&#8211; depending on the size of your scene (the amount and length of the takes, the amount of layers, number of objects, etc.) running a script on every take can take time to complete (good time to grab a coffee). If your scene is complex and large then please save first before running a batch script.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pyfbsdk import *\n\n#Define lSystem\nlSystem = FBSystem()\n\n# Store what take you are on before the script was run\nlOriginalTake = lSystem.CurrentTake\nprint lOriginalTake.Name + &amp;quot; was the take you were on&amp;quot; #some fun to remind you of where you were\n\n# On all Takes within the Scence\nfor take in FBSystem().Scene.Takes:\n#Merge all object in the scene to the BaseAnimation layer and delete the empty layers\nFBSystem().CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)\n\n# Return to the original take you were on before the script was run\nlSystem.CurrentTake = lOriginalTake\n#some fun to let you know where you are\nprint lSystem.CurrentTake.Name + &amp;quot; is the take you we brought you back to&amp;quot;\n<\/pre>\n<p>Storing lSystem.CurrentTake as lOriginalTake helps us return to the take we were on before running the script.<\/p>\n<p>&nbsp;<\/p>\n<p>I hope this helps.<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Being able to run a Python script on all takes within a MotionBuilder scene is a powerful time saver. Below I&#8217;m going to show how I learned to create a layer on every take within a MotionBuilder scene using Python. We are going to&nbsp;use Python to create an Animation Layer on all takes within our [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":129,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4],"tags":[5,7],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3936.jpg?fit=169%2C99","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-23","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":83,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/","url_meta":{"origin":127,"position":0},"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: [code language=\"python\"] from pyfbsdk import * lSystem\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":336,"url":"http:\/\/www.vicdebaie.com\/blog\/how-to-use-functions-with-motionbuilder-python\/","url_meta":{"origin":127,"position":1},"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":274,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-import-motionbuilder-characters-into-story\/","url_meta":{"origin":127,"position":2},"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":794,"url":"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-offset-all-animations-within-a-scene\/","url_meta":{"origin":127,"position":3},"title":"Using MotionBuilder Python To Offset All Animations Within A Scene","author":"admin","date":"January 7, 2021","format":false,"excerpt":"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\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\/2021\/01\/OffSet-1.jpg?fit=960%2C540&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=960%2C540&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2021\/01\/OffSet-1.jpg?fit=960%2C540&resize=700%2C400 2x"},"classes":[]},{"id":345,"url":"http:\/\/www.vicdebaie.com\/blog\/finding-a-characters-namespace-with-motionbuilder-python\/","url_meta":{"origin":127,"position":4},"title":"Finding a Character&#8217;s NameSpace with MotionBuilder Python","author":"admin","date":"April 25, 2017","format":false,"excerpt":"Here is a snippet of script that I use a lot when dealing with Character's Name Spaces within MotionBuilder. [code language=\"python\"] ##Setup variables to get all characters within the scene lAllChars = FBSystem().Scene.Characters ##Setup a variable to get the length of lAllChars - this will be used to creat a\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\/12463-nametag600.jpg?fit=950%2C534&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/12463-nametag600.jpg?fit=950%2C534&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/04\/12463-nametag600.jpg?fit=950%2C534&resize=700%2C400 2x"},"classes":[]},{"id":253,"url":"http:\/\/www.vicdebaie.com\/blog\/move-a-character-in-motionbuilder-to-the-worlds-center-with-python\/","url_meta":{"origin":127,"position":5},"title":"Move a Character in MotionBuilder to the World&#8217;s Center with Python","author":"admin","date":"March 7, 2018","format":false,"excerpt":"\u200eWith a dozen takes in my Motionbuilder scene and my Character placed at different locations on each take, I decided Python would help me move my Character to the World's Center. With raw Mocap data your Character's Wold Position is all based on the Actors position within the volume during\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\/02\/IMG_4056.jpg?fit=800%2C600&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?fit=800%2C600&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?fit=800%2C600&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/127"}],"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=127"}],"version-history":[{"count":12,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":827,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions\/827"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/129"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}