{"id":83,"date":"2017-02-09T07:08:58","date_gmt":"2017-02-09T12:08:58","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=83"},"modified":"2017-11-07T16:38:18","modified_gmt":"2017-11-07T21:38:18","slug":"using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/","title":{"rendered":"Using Python to Create a layer on the Current Selected Take in MotionBuilder.\u00a0"},"content":{"rendered":"<blockquote><p><img data-attachment-id=\"124\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/img_3935\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3935.png?fit=237%2C153\" data-orig-size=\"237,153\" 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_3935.png?fit=237%2C153\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3935.png?fit=237%2C153\" decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-124 alignnone alignleft\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_3935.png?resize=237%2C153\" alt=\"\" width=\"237\" height=\"153\" data-recalc-dims=\"1\" \/><\/p>\n<p style=\"text-align: left;\">In MotionBuilder using animation layers are great for edits, blending, additives and in general adding quality passes to your animations.<\/p>\n<p style=\"text-align: left;\">So below I&#8217;m going to demo how I learned to add layers\u00a0using Python.<\/p>\n<\/blockquote>\n<p>To create an Animation Layer on the Current Take script:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom pyfbsdk import *\r\n\r\nlSystem = FBSystem()\r\n\r\n##Create a new layer on the current take\r\nlSystem.CurrentTake.CreateNewLayer()\r\n# Get the Layer Count for the current take\r\nlCount = lSystem.CurrentTake.GetLayerCount()\r\n# Use the layer count to name the layer: &quot;lCount-1&quot; = top most layer, &quot;lCount-2&quot; = second top most layer, &quot;lCount-3&quot; = third from the top layer, etc.\r\nlSystem.CurrentTake.GetLayer(lCount-1).Name= &quot;Creat Through Python&quot;\r\n#Set the top most layer as the selected\/active one (Keys will be added to that layer)\r\n#if you have 5 Animation layers and want the second one from the top selected you would use &quot;lCount-2&quot;\r\nlSystem.CurrentTake.SetCurrentLayer(lCount-1)\r\n<\/pre>\n<p>Now let&#8217;s setup a Python Script to Merge all Layers and then Delete Merged Layers:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom pyfbsdk import *\r\n\r\nlSystem = FBSystem()\r\n\r\n#Merge all object in the scene to the BaseAnimation layer, delete the source layers if they are empty    \r\nFBSystem().CurrentTake.MergeLayers(FBAnimationLayerMergeOptions.kFBAnimLayerMerge_AllLayers_CompleteScene, True, FBMergeLayerMode.kFBMergeLayerModeAutomatic)\r\n\r\n#Info - Merge option for animation layers:\r\n# kFBAnimLayerMerge_SelectedLayers_SelectedProperties = Merge the animation of the selected properties of the selected models from the selected layers to the selected layer with the lowest index.\r\n# kFBAnimLayerMerge_AllLayers_SelectedProperties = Merge the animation of the selected properties of the selected models from all the layers to the BaseAnimation layer.\r\n# kFBAnimLayerMerge_SelectedLayers_AllProperties = Merge the animation of all properties of the selected models from the selected layers to the selected layer with the lowest index.\r\n# kFBAnimLayerMerge_AllLayers_AllProperties = Merge the animation of all properties of the selected models from all the layers to the BaseAnimation layer.\r\n# kFBAnimLayerMerge_SelectedLayers_CompleteScene = Merge the animation of all properties from the selected layers to the selected layer with the lowest index.\r\n# kFBAnimLayerMerge_AllLayers_CompleteScene  = Merge the animation of all properties from all the layers to the BaseAnimation layer.               \r\n\r\n<\/pre>\n<p>Since we used &#8220;kFBAnimLayerMerge_AllLayers_CompleteScene&#8221; all our Merged Layers were deleted leaving a clean layer stack \u00a0within the MotionBuilder take.<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>In MotionBuilder using animation layers are great for edits, blending, additives and in general adding quality passes to your animations. So below I&#8217;m going to demo how I learned to add layers\u00a0using Python. To create an Animation Layer on the Current Take script: from pyfbsdk import * lSystem = FBSystem() ##Create a new layer on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":124,"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_3935.png?fit=237%2C153","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-1l","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":83,"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":518,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-fbdelete\/","url_meta":{"origin":83,"position":1},"title":"MotionBuilder Python FBDelete","author":"admin","date":"April 23, 2018","format":false,"excerpt":"I've been asked a few times now on how to delete objects, files, takes, layers, etc. from MotionBuilder's Scenes. I thought I would take a few moments to go through the basics of FBDelete(). All examples below share pretty much the exact same structure with there scripts, we create an\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\/fbdelete.png?fit=420%2C294&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":590,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-library-aka-my-fav-functions\/","url_meta":{"origin":83,"position":2},"title":"MotionBuilder Python Library aka. My Fav Functions","author":"admin","date":"July 16, 2018","format":false,"excerpt":"\u00a0 Here is a quick post containing a collection of my favorite functions or snippets of scripts that I find very useful in my day to day workflow. You could save them all and then import them into your scripts as apart of your person library, to do that I\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\/07\/CheatSheet.jpg?fit=1200%2C797&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/07\/CheatSheet.jpg?fit=1200%2C797&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/07\/CheatSheet.jpg?fit=1200%2C797&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/07\/CheatSheet.jpg?fit=1200%2C797&resize=1050%2C600 3x"},"classes":[]},{"id":550,"url":"http:\/\/www.vicdebaie.com\/blog\/stop-foot-sliding-with-motionbuilder-and-python\/","url_meta":{"origin":83,"position":3},"title":"Stop Foot Sliding With MotionBuilder and Python","author":"admin","date":"June 11, 2018","format":false,"excerpt":"Update June 20 2022 -\u00a0 It's been a while since I have checked the blog. :( Back in January someone posted a comment asking if i ever updated this script\/tool to work with newer MotionBuilders. I have now, sorry for the wait. The fix was a quick change, Motionbuilder changed\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\/06\/footslide-1.jpg?fit=1200%2C800&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/06\/footslide-1.jpg?fit=1200%2C800&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/06\/footslide-1.jpg?fit=1200%2C800&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2018\/06\/footslide-1.jpg?fit=1200%2C800&resize=1050%2C600 3x"},"classes":[]},{"id":747,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-mirror-character-animation-through-story-mode\/","url_meta":{"origin":83,"position":4},"title":"MotionBuilder Python &#8211; Mirror Character Animation Through Story Mode","author":"admin","date":"November 21, 2019","format":false,"excerpt":"A quick script that will mirror animations via Story Mode.","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\/11\/Mirror-Cap.jpg?fit=960%2C640&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/11\/Mirror-Cap.jpg?fit=960%2C640&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/11\/Mirror-Cap.jpg?fit=960%2C640&resize=700%2C400 2x"},"classes":[]},{"id":81,"url":"http:\/\/www.vicdebaie.com\/blog\/plotting-character-animation-with-a-motionbuilder-python-script\/","url_meta":{"origin":83,"position":5},"title":"Plotting Character Animation With A MotionBuilder Python Script .\u00a0","author":"admin","date":"February 9, 2017","format":false,"excerpt":"Let's go over how to use Python to plot animation onto a character's Control Rig. The interesting part of this is\u00a0the \"plot options\" and how we call back on them when we plot. \u00a0 [code language=\"python\"] from pyfbsdk import * # Defining our Characater as the currnetly selected one lCharacter\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":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/83"}],"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=83"}],"version-history":[{"count":14,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":755,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/83\/revisions\/755"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/124"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}