{"id":216,"date":"2017-02-21T09:19:26","date_gmt":"2017-02-21T14:19:26","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=216"},"modified":"2017-11-07T16:34:54","modified_gmt":"2017-11-07T21:34:54","slug":"lock-and-plot-selected-properties-using-motionbuilders-python","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/lock-and-plot-selected-properties-using-motionbuilders-python\/","title":{"rendered":"Lock and Plot selected properties using MotionBuilder\u2019s Python."},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><img data-attachment-id=\"226\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/lock-and-plot-selected-properties-using-motionbuilders-python\/motionbuilder_locked_fcurve\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?fit=737%2C271\" data-orig-size=\"737,271\" 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\/motionbuilder_locked_fcurve.jpg?fit=300%2C110\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?fit=678%2C249\" decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-226 size-full\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?resize=678%2C249\" width=\"678\" height=\"249\" srcset=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?w=737 737w, https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/motionbuilder_locked_fcurve.jpg?resize=300%2C110 300w\" sizes=\"(max-width: 678px) 100vw, 678px\" data-recalc-dims=\"1\" \/><\/p>\n<p>I ran into a bug in my <a href=\"http:\/\/www.vicdebaie.com\/blog\/%EF%BB%BFplotting-selected-properties-using-motionbuilders-python\/\">previous post<\/a>\u00a0about Plotting Selected properties &#8211; 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 this problem myself.<\/p>\n<p>I wanted to reworking my script\u00a0to allow MotionBuilder to actually plot on selected properties. The solution for decoupling the two Transforms (Translation and Rotation) through Python scripting is to <strong>lock<\/strong> the Rotational Properties before plotting &#8211; the Scale seems to be working independent from the other two Transforms, so we continue to deal with it\u00a0through &#8220;.SetFocus(False)&#8221;.<\/p>\n<p>I will be combining a few of the Python scripts from my previous posts to into a new\u00a0script that will:<\/p>\n<ol>\n<li style=\"text-align: left;\">Create a new scene on run time<\/li>\n<li style=\"text-align: left;\">Create a Marker within that new scene<\/li>\n<li style=\"text-align: left;\">Animate the marker on its Translation, Rotation and Scaling<\/li>\n<li style=\"text-align: left;\">Select properties in which we want to Plot and de-select the ones we wished to not plot<\/li>\n<li style=\"text-align: left;\">Lock the Rotational properties<\/li>\n<li style=\"text-align: left;\">Plot the Marker<\/li>\n<\/ol>\n<p>The Resulting code was created in its entirety:<\/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\n'''\r\nHere is where we will start the attempt to plot on selected properties\r\n\r\nFirst we are going to animate the rotation and the scaling - this will have animation on all 3 transforms\r\n'''\r\n\r\n# Define the Transaltion to be represented as lmarker.Translation\r\nxTrans, yTrans, zTrans = lmarker.Translation\r\n# Define the Rotation to be represented as lmarker.Rotation\r\nxRot, yRot, zRot = lmarker.Rotation\r\n# Define the Scale to be represented as lmarker.Rotation\r\nxScl, yScl, zScl = lmarker.Scaling\r\n\r\n# Declare that lmarker.Translation, lmarker.Rotation and lmarker.Scale can be animated\r\nlmarker.Translation.SetAnimated(True)\r\nlmarker.Rotation.SetAnimated(True)\r\nlmarker.Scaling.SetAnimated(True)\r\n\r\n# Rotate lmarker.Rotation to 0 on the x axis, 0 on the y axis and 0 on the z axis &#x5B;0, 0, 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.Rotation.GetAnimationNode().KeyAdd(FBTime(0,0,0,0), &#x5B;0, 0, 0])\r\n\r\n# Rotate lmarker.Rotation to 3600 on the x, y and z axis &#x5B;3600, 3600, 3600].\r\n# I picked 3600 so that we can really see the result\r\n# Set a key at frame 200 (FBTime(0,0,0,200) - the time is the last 0 in the sequence\r\nlmarker.Rotation.GetAnimationNode().KeyAdd(FBTime(0,0,0,200), &#x5B;3600, 3600, 3600])\r\n\r\n# Scale lmarker.Scaling to 0 on the x axis, 0 on the y axis and 0 on the z axis &#x5B;0, 0, 0]\r\nlmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,0), &#x5B;1, 1, 1])\r\n\r\n# Scale lmarker.Scaling to 10 on the x, y and z axis &#x5B;10, 10, 10].\r\n# Set a key at frame 200 (FBTime(0,0,0,200) - the time is the last 0 in the sequence\r\nlmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,100), &#x5B;5, 5, 5])\r\n\r\n# Scale lmarker.Scaling to 0 on the x axis, 0 on the y axis and 0 on the z axis &#x5B;0, 0, 0]\r\nlmarker.Scaling.GetAnimationNode().KeyAdd(FBTime(0,0,0,200), &#x5B;1, 1, 1])\r\n\r\n''' now let's plot only the translation animations and leave the rotation and scaling untouched '''\r\n# Search the objects PropertyList and find &quot;Lcl Translation, Lcl Rotation and Lcl Scaling&quot;\r\nlTranslation = lmarker.PropertyList.Find( 'Lcl Translation' )\r\nlRotation = lmarker.PropertyList.Find( 'Lcl Rotation' )\r\nlScaling = lmarker.PropertyList.Find( 'Lcl Scaling' )\r\n\r\n# Select the marker's Translation fcurves using SetFocus\r\nlTranslation.SetFocus(True)\r\n#Ensure the marker's Rotation and Scaling is not selected\r\nlRotation.SetFocus(False)\r\nlScaling.SetFocus(False)\r\n\r\n'''\r\nMotionBuilder 2015 couples the Translation and the Rotation during &quot;PlotTakeOnSelectedProperties&quot;, we will \r\nLock the Rotation of our object - this should prevent the plotting from occurring on the Marker's Rotational X,Y and Z axis&quot;\r\n'''\r\n\r\n# Set all Local Rotational Axis to be locked\r\nlRotation.SetLocked( True )\r\n\r\n'''\r\nif we wanted to lock individual axis we would use the &quot;.SetMemberLocked( # , True )&quot;\r\n\r\nlRotation.SetMemberLocked( 0 , True ) = Local Rotational X axis\r\nlRotation.SetMemberLocked( 1 , True ) = Local Rotational Y axis\r\nlRotation.SetMemberLocked( 2 , True ) = Local Rotational Z axis\r\n'''\r\n\r\n#Plot the Marker's Selected Properties \r\nFBSystem().CurrentTake.PlotTakeOnSelectedProperties( FBTime(0,0,0,1))\r\n\r\n#Unlock the Rotation Properties\r\nlRotation.SetLocked( False )\r\n<\/pre>\n<p>Viola! It worked! \ud83d\ude42<\/p>\n<p>The Locking of the Properties can be done easily enough through MotionBuilder&#8217;s Python Editor as seen here:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# Search the objects PropertyList and find &quot;Lcl Rotation&quot;\r\nlRotation = lmarker.PropertyList.Find( 'Lcl Rotation' )\r\n\r\n#Set the Lock to be True or False\r\nlRotation.SetLocked = True\r\n#This line was added to the end of the script because later on we may want to have access to these properties\r\nlRotation.SetLocked = False\r\n<\/pre>\n<p>Note the difference between &#8220;.SetLocked&#8221; and &#8220;.SetMemberLocked&#8221;:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#SetLocked works on the Local Transform as a whole (X, Y, and Z)\r\nlRotation.SetLocked( True )\r\n\r\n#SetLockedMembers works per axis for the Local Transform\r\n#Each axis is represented and a number 0, 1 and 2 = X, Y and Z.\r\nlRotation.SetMemberLocked( 0 , True )\r\nlRotation.SetMemberLocked( 1 , True )\r\nlRotation.SetMemberLocked( 2 , True )\r\n<\/pre>\n<p>I would rather not do this\u00a0work around, but it did allow me to explore and learn about locking properties\u00a0using the &#8220;.SetLocked&#8221; and &#8220;.SetMemeberLocked&#8221; within Motionbuilder.<\/p>\n<p>Overall this was great fun and very satisfying.<\/p>\n<p>I hope this helps.<\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>&nbsp; I ran into a bug in my previous post\u00a0about Plotting Selected properties &#8211; 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 this problem myself. I wanted [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":226,"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\/motionbuilder_locked_fcurve.jpg?fit=737%2C271","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-3u","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":216,"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":81,"url":"http:\/\/www.vicdebaie.com\/blog\/plotting-character-animation-with-a-motionbuilder-python-script\/","url_meta":{"origin":216,"position":1},"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":83,"url":"http:\/\/www.vicdebaie.com\/blog\/using-python-to-create-a-layer-on-the-current-selected-take-in-motionbuilder\/","url_meta":{"origin":216,"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":292,"url":"http:\/\/www.vicdebaie.com\/blog\/mirroring-motionbuilder-character-animation-with-python\/","url_meta":{"origin":216,"position":3},"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":566,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-parent-constraint-tool\/","url_meta":{"origin":216,"position":4},"title":"MotionBuilder Python Parent Constraint Tool","author":"admin","date":"June 18, 2018","format":false,"excerpt":"Here is a quick post to share a tool I created a little while back. It is designed to help to quickly create Parent Constraints between two objects as well as easily allow the user to bake that constraint down. The script can be found HERE and there are 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\/02\/img_3937.jpg?fit=443%2C364&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":620,"url":"http:\/\/www.vicdebaie.com\/blog\/using-your-currently-selected-character-to-generate-a-list-of-all-fk-and-ik-models-with-motionbuilder-python\/","url_meta":{"origin":216,"position":5},"title":"Using Your Currently Selected Character To Generate A List Of All FK And IK Models With MotionBuilder Python","author":"admin","date":"September 7, 2018","format":false,"excerpt":"Here is a quick post that will help use your currently selected character to generate lists of all FK and IK models. When ever possible I like to use these funcitons as opposed to generating the list by hand and storing that as a variable. I can't remember where 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\/09\/fkiklist.jpg?fit=522%2C397&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/216"}],"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=216"}],"version-history":[{"count":14,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":444,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/216\/revisions\/444"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/226"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}