{"id":253,"date":"2018-03-07T14:08:27","date_gmt":"2018-03-07T19:08:27","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=253"},"modified":"2018-03-07T14:08:27","modified_gmt":"2018-03-07T19:08:27","slug":"move-a-character-in-motionbuilder-to-the-worlds-center-with-python","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/move-a-character-in-motionbuilder-to-the-worlds-center-with-python\/","title":{"rendered":"Move a Character in MotionBuilder to the World&#8217;s Center with Python"},"content":{"rendered":"<p style=\"text-align: left;\"><img data-attachment-id=\"256\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/move-a-character-in-motionbuilder-to-the-worlds-center-with-python\/img_4056\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?fit=800%2C600\" data-orig-size=\"800,600\" 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_4056.jpg?fit=300%2C225\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?fit=678%2C509\" decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-256 size-medium aligncenter\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?resize=300%2C225\" width=\"300\" height=\"225\" srcset=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?resize=300%2C225 300w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?resize=768%2C576 768w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?resize=533%2C400 533w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/IMG_4056.jpg?w=800 800w\" sizes=\"(max-width: 300px) 100vw, 300px\" data-recalc-dims=\"1\" \/>\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&#8217;s Center.<\/p>\n<p>With raw Mocap data your Character&#8217;s Wold Position is all based on the Actors position within the volume during the capture (obvious). When working with a single Character I prefer to have \u00a0the Character positioned at the World&#8217;s Center.<\/p>\n<p>Placing the Character at the World&#8217;s Center not only makes the math easier when supporting coverage of angles or distance, but it also keeps the scene organized and clean. Another nice thing is having the animations start frame reside on frame zero.<\/p>\n<p>With Python being my new best friend within MotionBuilder I thought &#8220;I can script this!&#8221;.<\/p>\n<p>I will go through my script for moving our test Character to the World Center below:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom pyfbsdk import *\r\n\r\n##This Will Have To Be Changed To Reflect Your Charcter's Hip Name\r\n##For This Test I Am Using Mia And Her Hips Are &quot;Mia_Ctrl:HipsEffector&quot;\r\nlHipsEffector = FBFindModelByLabelName(&quot;Mia_Ctrl:HipsEffector&quot;)\r\n\r\n##Get The Amount Of Frames That Are Within The Active Time Line\r\n'''\r\nWe Will Need This As We Will Be Shifting Our Data Along The Time Line And We Want To Respect The Original Length Of The Time Line.\r\n'''    \r\ndef GetFrameCount():\r\n    ##Goto Start Frame And Store Frame Number\r\n    FBPlayerControl().GotoStart()\r\n    GetFrameCount.StartFrame = FBSystem().LocalTime.GetFrame()\r\n    ##Goto End Frame And Store Frame Number\r\n    FBPlayerControl().GotoEnd()\r\n    GetFrameCount.EndFrame = FBSystem().LocalTime.GetFrame()\r\n    ##Subtract Start Time From End Time To Get Our Time Span\r\n    GetFrameCount.TimeSpan = GetFrameCount.EndFrame - GetFrameCount.StartFrame\r\n\r\n##Create A Story Clip And Translate The Data To Start At The World Center     \r\ndef CreateStoryClip():\r\n    ##Create A Track For Our Character:\r\n    lTrack = FBStoryTrack(FBStoryTrackType.kFBStoryTrackCharacter, FBStory().RootFolder)\r\n    ##Assign Our Current Character To The Track\r\n    lTrack.Details.append(FBApplication().CurrentCharacter)\r\n    ##Name Track\r\n    lTrack.Label = &quot;Del_Me-PythonStoryClip&quot;\r\n    ##Insert Current Take In The Newly Created Track\r\n    CreateStoryClip.lClip = lTrack.CopyTakeIntoTrack( FBSystem().CurrentTake.LocalTimeSpan, FBSystem().CurrentTake )\r\n    \r\n    ##Move On Time Line To Prevent A Mobu Up Date Bug - This Has To Be Done To Ensure We Get The Correct Coordinates For The Hips\r\n    FBPlayerControl().GotoNextKey()\r\n    FBSystem().Scene.Evaluate()\r\n    FBPlayerControl().GotoStart()\r\n    FBSystem().Scene.Evaluate()\r\n    \r\n    ##Set Variable lCiplOffSet Off Of The Current Character's Hips Translational Values\r\n    lClipOffSet = lHipsEffector.Translation\r\n    ##Set Variables lClipOffSetX, lClipOffSetY, lClipOffSetZ\r\n    lClipOffSetX, lClipOffSetY, lClipOffSetZ = lClipOffSet\r\n    ##Set Variables lClipOffSetX, lClipOffSetY, lClipOffSetZ To Be A Negative Concatenate String\r\n    lClipOffSetX, lClipOffSetY, lClipOffSetZ = -lClipOffSetX, -lClipOffSetY, -lClipOffSetZ\r\n    ##Offset Clip To Start At The World Center\r\n    CreateStoryClip.lClip.Translation = FBVector3d(lClipOffSetX, 0, lClipOffSetZ)\r\n\r\ndef ShiftStoryClip():\r\n    ##Move Clip To Start At Frame Zero\r\n    lMyStartTime = 0\r\n    CreateStoryClip.lClip.Start = FBTime(0,0,0,lMyStartTime)\r\n\r\n##Set The Time Line To Start At Zero And Be As Long As The GetFrameCount.TimeSpan Value\r\ndef StartTimeLineAtZero():\r\n    ##Set Our Timeline To Be ==  GetFrameCount.TimeSpan In Length\r\n    ##FBTime (0, 0, 0, 0, 0) = (Hours, Minutes, Seconds, Frames, Fields)\r\n    FBSystem().CurrentTake.LocalTimeSpan = FBTimeSpan(FBTime(0, 0, 0, 0, 0), FBTime(0, 0, 0, GetFrameCount.TimeSpan, 0))\r\n\r\ndef PlotStoryClip():\r\n    ##Deal With The User's Sory Mode Activity\r\n    FBStory().Mute = False\r\n    \r\n    ##Plot Options\r\n    lPlotClipOptions = FBPlotOptions()\r\n    lPlotClipOptions.ConstantKeyReducerKeepOneKey = False\r\n    lPlotClipOptions.PlotAllTakes = False\r\n    lPlotClipOptions.PlotOnFrame = True\r\n    lPlotClipOptions.PlotPeriod = FBTime( 0, 0, 0, 1 )\r\n    lPlotClipOptions.PlotTranslationOnRootOnly = False\r\n    lPlotClipOptions.PreciseTimeDiscontinuities = False\r\n    lPlotClipOptions.RotationFilterToApply = FBRotationFilter.kFBRotationFilterUnroll\r\n    lPlotClipOptions.UseConstantKeyReducer = False\r\n    ##Plot Story Clip On Current Character\r\n    lChar = FBApplication().CurrentCharacter\r\n    lChar.PlotAnimation(FBCharacterPlotWhere.kFBCharacterPlotOnControlRig,lPlotClipOptions )\r\n    \r\n    ##Now To Delete Our Story Clip By Searching For &quot;Del_Me-PythonStoryClip&quot;\r\n    for eachTrack in FBStory().RootFolder.Tracks:\r\n        if eachTrack.Name == &quot;Del_Me-PythonStoryClip&quot;:\r\n            eachTrack.FBDelete()\r\n        else:\r\n            pass\r\n\r\n##Run Functions In The Correct Order\r\ndef ProcessTake(): \r\n    GetFrameCount()\r\n    CreateStoryClip()\r\n    ShiftStoryClip()\r\n    StartTimeLineAtZero()\r\n    PlotStoryClip()\r\n\r\n##Process Our Scene\r\nProcessTake()\r\n<\/pre>\n<p>This was fun! I found I was able to apply a lot of things I had learned over my short time exploring MotionBuilder&#8217;s Python Editor. The process (like all challenges) became problematic and solutions took time to figure out, but the sense of accomplishment is always amazing.<\/p>\n<p>I hope this helps.<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>\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&#8217;s Center. With raw Mocap data your Character&#8217;s Wold Position is all based on the Actors position within the volume during the capture (obvious). When working [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":256,"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_4056.jpg?fit=800%2C600","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-45","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":253,"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":345,"url":"http:\/\/www.vicdebaie.com\/blog\/finding-a-characters-namespace-with-motionbuilder-python\/","url_meta":{"origin":253,"position":1},"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":276,"url":"http:\/\/www.vicdebaie.com\/blog\/saving-motionbuilder-character-animation-with-python\/","url_meta":{"origin":253,"position":2},"title":"Saving MotionBuilder Character Animation with Python","author":"admin","date":"April 5, 2017","format":false,"excerpt":"When I get Mocap it'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\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\/03\/img_4059-1.jpg?fit=300%2C200&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":686,"url":"http:\/\/www.vicdebaie.com\/blog\/save-all-story-clips-to-new-takes-with-motionbuilder-python-script\/","url_meta":{"origin":253,"position":3},"title":"Save All Story Clips To New Takes with MotionBuilder Python Script","author":"admin","date":"May 2, 2019","format":false,"excerpt":"UPDATED: A quick update that will now allow the script to maintain all of the original tracks within the story. The story will look exactly as it was pre-processing. Thanks Simon Kay Below is a script that I wrote, It goes through all you Story tracks and clips and then\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\/2019\/05\/StoryTrackClips.png?fit=851%2C304&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/05\/StoryTrackClips.png?fit=851%2C304&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2019\/05\/StoryTrackClips.png?fit=851%2C304&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":253,"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":528,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-clean-character-from-scene-with-fbdelete\/","url_meta":{"origin":253,"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\/253"}],"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=253"}],"version-history":[{"count":7,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":488,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions\/488"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/256"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}