{"id":276,"date":"2017-04-05T08:18:45","date_gmt":"2017-04-05T12:18:45","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=276"},"modified":"2017-11-06T09:16:50","modified_gmt":"2017-11-06T14:16:50","slug":"saving-motionbuilder-character-animation-with-python","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/saving-motionbuilder-character-animation-with-python\/","title":{"rendered":"Saving MotionBuilder Character Animation with Python"},"content":{"rendered":"<p><img data-attachment-id=\"279\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/saving-motionbuilder-character-animation-with-python\/img_4059-jpg\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/03\/img_4059.jpg?fit=300%2C200\" data-orig-size=\"300,200\" 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;1&quot;}\" data-image-title=\"img_4059.jpg\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/03\/img_4059.jpg?fit=300%2C200\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/03\/img_4059.jpg?fit=300%2C200\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-279\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/03\/img_4059.jpg?resize=300%2C200\" alt=\"\" width=\"300\" height=\"200\" data-recalc-dims=\"1\" \/><br \/>\nWhen I get Mocap it&#8217;s usually in a messy scene. Optics, Markets, strange NameSpace, etc. they all can bog down a scene. One of the first thing I do is save out the Character Animation and load it back into a clean scene.<\/p>\n<p>Using Python to save out Character Animation is great! Python can help ensure consistency with the pipeline you set up.<\/p>\n<p>I did some searching and was able to find some info that allowed me to quickly creat a script that would do the following:<\/p>\n<ul>\n<li>Check for a folder structure and if it does not exist then the script will creat one.<\/li>\n<li>Set up options in which to save the current Character&#8217;s Animations.<\/li>\n<li>Save out Character Animation \u00a0.fbx files.<\/li>\n<\/ul>\n<p>The end result of the script&#8217;s out put would look like this:<\/p>\n<p>&#8220;C:\\MBChrAnimFiles\\SceneName\\SceneName&#8211;CharacterNameSpace.fbx&#8221;<\/p>\n<p>I thought organizing the data this way would be helpful if I ever had to go back to my original Raw Data, the folder and file structure tells me what the original file was named and what Character it was saved from.<\/p>\n<p>Save Character Animation Script:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom pyfbsdk import *\r\nimport os\r\nfrom time import gmtime, strftime\r\n\r\nlSystem = FBSystem()\r\nlApp = FBApplication()\r\n\r\nlSaveCharCurrent = lApp.CurrentCharacter\r\nlSaveCharCurrentName = lSaveCharCurrent.LongName&#x5B;:-10]\r\nlSaveTakeNameCurrent = lSystem.CurrentTake.Name\r\nlSaveFBXFileFullName = lApp.FBXFileName\r\n\r\n# The place you want your animations to be saved\r\nlSaveDirRoot = r&quot;C:\\MBChrAnimFiles&quot;\r\n\r\n# Variables for the sub folder and scene name\r\nlSaveDirSub = os.path.splitext(os.path.basename(lSaveFBXFileFullName))&#x5B;0]\r\nlSaveSceneName = os.path.splitext(os.path.basename(lSaveFBXFileFullName))&#x5B;0]\r\n\r\n# Variable for the paths\r\nlSavePath = lSaveDirRoot + &quot;\\\\&quot; + lSaveDirSub + &quot;\\\\&quot;\r\n\r\n# Variable for the file name\r\nlSaveFileName = lSaveSceneName + &quot;--&quot; + lSaveCharCurrentName\r\n\r\n# Variable for the full path &quot;Root\\SubFolder\\FileName&quot;\r\nlSaveChrAnim = lSavePath + lSaveFileName\r\n  \r\n# Directory setup to save in (if director it not there then we make it)\r\nif not os.path.exists(lSavePath):\r\n    os.makedirs(lSavePath)    \r\n\r\n# Save Animation Options    \r\nlSaveOptions = FBFbxOptions (False) # false = will not save options \r\nlSaveOptions.SaveCharacter = True\r\nlSaveOptions.SaveControlSet = True\r\nlSaveOptions.SaveCharacterExtention = True\r\nlSaveOptions.ShowFileDialog = False\r\nlSaveOptions.ShowOptionslDialog = False\r\n\r\nprint lSaveCharCurrentName + &quot;'s Data from &quot; + lSaveSceneName + &quot; is being saved. Please wait....&quot;\r\n\r\n# Save out animation\r\nlApp.SaveCharacterRigAndAnimation(lSaveChrAnim, lSaveCharCurrent, lSaveOptions)\r\n\r\nprint lSaveCharCurrentName + &quot;'s Data from &quot; + lSaveSceneName + &quot; has been saved.&quot;\r\n<\/pre>\n<p>This was one of those tools that I love. Running the script saves you from a number of clicks and also so much typing &#8211; it allows you to click and move on with your creation. \ud83d\ude42<\/p>\n<p>A big thanks to <a href=\"http:\/\/www.eksod.com\">Eduardo Simioni<\/a>, I was lucky to work with him on Assassin&#8217;s Unity. He is a great guy who has an awesome blog full of Python knowledge and Animation Tech, I wish I still worked with him as he is a wealth on knowledge &#8211; thank you Eduardo.<\/p>\n<p>I hope this helps.<\/p>\n<p>&nbsp;<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>When I get Mocap it&#8217;s usually in a messy scene. Optics, Markets, strange NameSpace, etc. they all can bog down a scene. One of the first thing I do is save out the Character Animation and load it back into a clean scene. Using Python to save out Character Animation is great! Python can help [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":280,"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\/03\/img_4059-1.jpg?fit=300%2C200","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-4s","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":81,"url":"http:\/\/www.vicdebaie.com\/blog\/plotting-character-animation-with-a-motionbuilder-python-script\/","url_meta":{"origin":276,"position":0},"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":[]},{"id":292,"url":"http:\/\/www.vicdebaie.com\/blog\/mirroring-motionbuilder-character-animation-with-python\/","url_meta":{"origin":276,"position":1},"title":"Mirroring MotionBuilder Character Animation with Python","author":"admin","date":"March 13, 2017","format":false,"excerpt":"In a previous post I went over \"Plotting and Plot Options\" as well as \"dir\" where we exposed the \"MirrorMode\" of a Character. Now with all that information exposed I will show you how I created a simple script that will mirror a\u00a0Character's animation, first by setting the \"MirrorMode\" to\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_4039-1.jpg?resize=350%2C200","width":350,"height":200},"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":276,"position":2},"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":747,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-mirror-character-animation-through-story-mode\/","url_meta":{"origin":276,"position":3},"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":794,"url":"http:\/\/www.vicdebaie.com\/blog\/using-motionbuilder-python-to-offset-all-animations-within-a-scene\/","url_meta":{"origin":276,"position":4},"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":274,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-import-motionbuilder-characters-into-story\/","url_meta":{"origin":276,"position":5},"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":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/276"}],"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=276"}],"version-history":[{"count":6,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/276\/revisions"}],"predecessor-version":[{"id":320,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/276\/revisions\/320"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/280"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=276"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}