{"id":172,"date":"2017-02-16T12:20:05","date_gmt":"2017-02-16T17:20:05","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=172"},"modified":"2017-11-06T09:16:51","modified_gmt":"2017-11-06T14:16:51","slug":"animating-and-setting-keys-with-motionbuilders-python-editor","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/animating-and-setting-keys-with-motionbuilders-python-editor\/","title":{"rendered":"Animating and setting keys with MotionBuilder&#8217;s Python Editor"},"content":{"rendered":"<p><img data-attachment-id=\"203\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/animating-and-setting-keys-with-motionbuilders-python-editor\/animatewithcode\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/AnimateWithCode.jpg?fit=600%2C220\" data-orig-size=\"600,220\" 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\/AnimateWithCode.jpg?fit=300%2C110\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/AnimateWithCode.jpg?fit=600%2C220\" decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-203\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/AnimateWithCode.jpg?resize=600%2C220\" alt=\"\" width=\"600\" height=\"220\" srcset=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/AnimateWithCode.jpg?w=600 600w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/AnimateWithCode.jpg?resize=300%2C110 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" data-recalc-dims=\"1\" \/><\/p>\n<p>Here is the code for a Python script that I wrote dealing animating and setting keys on a selected object within MotionBuilder. Writing this animation script really helped me get a better understanding on how to\u00a0use MotionBuilder&#8217;s FBTime. The exercise forced me to sit down for about two hours and research 3 of the major things that we as animators manipulate &#8211; Time, Keys, and Transforms.<\/p>\n<p>I hope this helps others and I really look forward to spending more time with fun scripts like this.<\/p>\n<p><!--more--><\/p>\n<p>A big thanks goes to <a href=\"http:\/\/awforsythe.com\/\">Alex Forsythe&#8217;s<\/a> video\u00a0<a href=\"http:\/\/awforsythe.com\/tutorials\/pyfbsdk-5\">&#8220;Python Scripting in MotionBuilder &#8211; 05 &#8211; FBTime and Playback Control&#8221;<\/a>.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom pyfbsdk import *\r\n\r\n# Get the instance of FBApplication, and clear the scene with FileNew().\r\napp = FBApplication()\r\napp.FileNew()\r\n\r\n# import time to allow us to access time line controls and play back controls\r\nimport time\r\n\r\n# ensure new scene is set to 30 fps and that the time line is shown as frames\r\nFBPlayerControl().SetTransportFps(FBTimeMode.kFBTimeMode30Frames)\r\nFBPlayerControl().TransportTimeFormat = FBTransportTimeFormat.kFBTimeFormatFrame\r\n\r\n# Set our Timeline to be 200 frames in length\r\nFBSystem().CurrentTake.LocalTimeSpan = FBTimeSpan(\r\n    # set start frame (0, 0, 0, 0, 0) = (hours, minutes, seconds, frames, fields)\r\n    FBTime(0, 0, 0, 0, 0),\r\n    # end frame\r\n    FBTime(0, 0, 0, 200, 0)\r\n    # if you wanted to set the time line to be 3 minutes long you could do some of the following to achieve that:\r\n    #in frames = (0, 0, 0, 5400, 0)\r\n    #in seconds = (0, 0, 180, 0, 0)\r\n    #in minutes = (0, 3, 0, 0, 0) \r\n    )\r\n\r\n# Creat an object that we will animate\r\nlmarker = FBModelMarker('VicMarker')\r\nlmarker.Show = True\r\nlmarker.Size = 1000\r\nlmarker.PropertyList.Find('LookUI').Data=1\r\nlmarker.Color = FBColor(0,1,1)\r\nlmarker.Selected = True\r\n\r\n# Define the Transaltion to be represented as lmarker.Translation\r\nxTrans, yTrans, zTrans = lmarker.Translation\r\n\r\n# Declare that lmarker.Translation can be animated\r\nlmarker.Translation.SetAnimated(True)\r\n\r\n# Position lmarker.Translation to 0 on the x axis, 250 on the y axis and 0 on the z axis &#x5B;0, 250, 0]\r\n# Set a key at frame 0 (FBTime(0,0,0,0) - the time is the last 0 in the sequence\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,0), &#x5B;0, 250, 0])\r\n\r\n# Position lmarker.Translation to -200 on the x axis, -150 on the y axis and 200 on the z axis &#x5B;-200, -150, 200]\r\n# Set a key at frame 25 (FBTime(0,0,0,25)\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,25), &#x5B;-200, 150, 200])\r\n# Set a key at frame 50 (FBTime(0,0,0,50) with x,y and z translation values\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,50), &#x5B;0, 0, 400])\r\n# Set a key at frame 75......\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,75), &#x5B;200, -150, 250])\r\n# etc. for the remaining 5 translation keys that will be set on frames 100, 125, 150, 175 and finally our last frame 200  \r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,100), &#x5B;0, -250, 0])\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,125), &#x5B;-200, -150, -250])\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,150), &#x5B;0, 0, -400])\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,175), &#x5B;200, 150, -200])\r\nlmarker.Translation.GetAnimationNode().KeyAdd(FBTime(0,0,0,200), &#x5B;0, 250, 0])\r\n\r\nprint &quot;BAM! YOU JUST ANIMATED WITH PYTHON! :)&quot;\r\n\r\n\r\n\r\n<\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Here is the code for a Python script that I wrote dealing animating and setting keys on a selected object within MotionBuilder. Writing this animation script really helped me get a better understanding on how to\u00a0use MotionBuilder&#8217;s FBTime. The exercise forced me to sit down for about two hours and research 3 of the major [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":203,"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\/AnimateWithCode.jpg?fit=600%2C220","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-2M","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":175,"url":"http:\/\/www.vicdebaie.com\/blog\/%ef%bb%bfplotting-selected-properties-using-motionbuilders-python\/","url_meta":{"origin":172,"position":0},"title":"\ufeffPlotting selected properties using MotionBuilder&#8217;s Python.","author":"admin","date":"February 17, 2017","format":false,"excerpt":"I ran\u00a0the script I created in \"Animating and setting keys with MotionBuilder's Python Editor\"\u00a0and decided that I would use the scene it creates\u00a0to learn how to plot on selected properties in MotionBuilder's Python Editor. Update: I found a work around for the bug and it is covered in my \"lock-and-plot-selected-properties-using-motionbuilders-python\"\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":288,"url":"http:\/\/www.vicdebaie.com\/blog\/getting-information-on-motionbuilders-python-with-dir\/","url_meta":{"origin":172,"position":1},"title":"Getting information on MotionBuilder&#8217;s Python with dir","author":"admin","date":"March 13, 2017","format":false,"excerpt":"Trying to figure how things work in MotionBuilder's Python editor is tough. Google and the SDK Help that comes along with MotionBuilder are great, but there is still more help out there - the \"dir\"! :) What does \"dir\" do? The definition I was able to find is \"It gives\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":81,"url":"http:\/\/www.vicdebaie.com\/blog\/plotting-character-animation-with-a-motionbuilder-python-script\/","url_meta":{"origin":172,"position":2},"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":253,"url":"http:\/\/www.vicdebaie.com\/blog\/move-a-character-in-motionbuilder-to-the-worlds-center-with-python\/","url_meta":{"origin":172,"position":3},"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":[]},{"id":216,"url":"http:\/\/www.vicdebaie.com\/blog\/lock-and-plot-selected-properties-using-motionbuilders-python\/","url_meta":{"origin":172,"position":4},"title":"Lock and Plot selected properties using MotionBuilder\u2019s Python.","author":"admin","date":"February 21, 2017","format":false,"excerpt":"\u00a0 I ran into a bug in my previous post\u00a0about Plotting Selected properties - a bug that occurs in MotionBuilder 2015. I got in touch with Discreet and they said it would be easy enough for them to fix the\u00a0bug in an update\/hot fix, but I really wanted to solve\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\/motionbuilder_locked_fcurve.jpg?fit=737%2C271&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?fit=737%2C271&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?fit=737%2C271&resize=700%2C400 2x"},"classes":[]},{"id":292,"url":"http:\/\/www.vicdebaie.com\/blog\/mirroring-motionbuilder-character-animation-with-python\/","url_meta":{"origin":172,"position":5},"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":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/172"}],"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=172"}],"version-history":[{"count":6,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":392,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/172\/revisions\/392"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/203"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}