{"id":104,"date":"2017-04-04T10:11:27","date_gmt":"2017-04-04T14:11:27","guid":{"rendered":"http:\/\/www.vicdebaie.com\/blog\/?p=104"},"modified":"2019-04-29T12:45:08","modified_gmt":"2019-04-29T16:45:08","slug":"creat-a-button","status":"publish","type":"post","link":"http:\/\/www.vicdebaie.com\/blog\/creat-a-button\/","title":{"rendered":"Create a button"},"content":{"rendered":"<p><img data-attachment-id=\"141\" data-permalink=\"http:\/\/www.vicdebaie.com\/blog\/creat-a-button\/tool_button\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/tool_button.jpg?fit=600%2C140\" data-orig-size=\"600,140\" 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\/tool_button.jpg?fit=300%2C70\" data-large-file=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/tool_button.jpg?fit=600%2C140\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-141 size-full aligncenter\" src=\"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/tool_button-e1486664421612.jpg?resize=600%2C140\" width=\"600\" height=\"140\"  data-recalc-dims=\"1\"><\/p>\n<p>Python scripts are great, they are even better when we can click a button to run them. A small GUI like the image shown (&#8220;Do it!&#8221; Button) can be very easy to set up.<\/p>\n<p>Thanks to <a href=\"http:\/\/neill3d.com\/en\/motionbuilder\/plaginy-pod-motionbuilder#UIBuilder_plugin\">neil3d.com<\/a>&#8216;s UI Builder Tool, this was valuable in creating a setup script that I could dissect and learn from. His <a href=\"http:\/\/neill3d.com\/en\/\">website<\/a> is a great source of information.<\/p>\n<p>Below I will go over how I learned to set up a Python script that will launch from a button click in MotionBuilder.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\n'''=================================\n|     Written by Victor DeBaie     |\n|  http:\/\/www.vicdebaie.com\/blog\/  |\n|      vic_debaie@hotmail.com      |\n================================='''\n\nfrom pyfbsdk import *\nfrom pyfbsdk_additions import *\n\n# VAriable &quot;DoIt&quot; as a Button\nDoIt = FBButton()\n\n# Define what the &quot;DoIt&quot; button does when clicked\ndef BtnCallbackDoIt(control, event):\nprint &quot;do it!&quot;\n\n# Start of the tool window lay out\ndef PopulateTool(t):\n#populate regions here\n\n# Layout for the Button\n# the DoIt button's position on the x\nx = FBAddRegionParam(15,FBAttachType.kFBAttachNone,&quot;&quot;)\n# the DoIt button's position on the y\ny = FBAddRegionParam(10,FBAttachType.kFBAttachNone,&quot;&quot;)\n# the DoIt button's width\nw = FBAddRegionParam(150,FBAttachType.kFBAttachNone,&quot;&quot;)\n# the DoIt button's height\nh = FBAddRegionParam(65,FBAttachType.kFBAttachNone,&quot;&quot;)\n\nt.AddRegion(&quot;DoIt&quot;,&quot;DoIt&quot;, x, y, w, h)\n\nt.SetControl(&quot;DoIt&quot;, DoIt)\nDoIt.Visible = True\nDoIt.ReadOnly = False\nDoIt.Enabled = True\n# hover over the button and this msg. will apear\nDoIt.Hint = &quot;launches what ever script you are testing - NOT FOR PRODUCTION&quot;\n# the text that will appear on the button\nDoIt.Caption = &quot;Do it!&quot;\nDoIt.State = 0\n# the button style - read up on this, there are lots of functions to be had\nDoIt.Style = FBButtonStyle.kFBPushButton\n# the button's text will be centered\nDoIt.Justify = FBTextJustify.kFBTextJustifyCenter\nDoIt.Look = FBButtonLook.kFBLookNormal\n# this tells the button &quot;when you are clicked go to def BtnCallbackDoIt&quot;\nDoIt.OnClick.Add(BtnCallbackDoIt)\n\ndef CreateTool():\n# the tool window's name\nt = FBCreateUniqueTool(&quot;Tool&quot;)\n# the tool window's width\nt.StartSizeX = 200\n# the tool window's height\nt.StartSizeY = 120\nPopulateTool(t)\nShowTool(t)\nCreateTool()\n\n<\/pre>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Python scripts are great, they are even better when we can click a button to run them. A small GUI like the image shown (&#8220;Do it!&#8221; Button) can be very easy to set up. Thanks to neil3d.com&#8216;s UI Builder Tool, this was valuable in creating a setup script that I could dissect and learn from. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":141,"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,11],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.vicdebaie.com\/blog\/wp-content\/uploads\/2017\/02\/tool_button.jpg?fit=600%2C140","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8pltq-1G","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":104,"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":190,"url":"http:\/\/www.vicdebaie.com\/blog\/motionbuilder-python-tool-saveit\/","url_meta":{"origin":104,"position":1},"title":"MotionBuilder Python Tool &#8220;SaveIt&#8221;","author":"admin","date":"February 12, 2017","format":false,"excerpt":"Here is a script\/tool I created for MotionBuilder using Python. \u00a0This tool will\u00a0do an incremental save of your scene. Why? Incremental saves are amazingly useful, I thought a tool that automates the process down to one click would be fun. A big thanks goes out to my college Raphael Lappiere\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\/SaveIt_tool.jpg?fit=600%2C220&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":104,"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":288,"url":"http:\/\/www.vicdebaie.com\/blog\/getting-information-on-motionbuilders-python-with-dir\/","url_meta":{"origin":104,"position":3},"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":127,"url":"http:\/\/www.vicdebaie.com\/blog\/running-a-python-script-on-all-takes\/","url_meta":{"origin":104,"position":4},"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":336,"url":"http:\/\/www.vicdebaie.com\/blog\/how-to-use-functions-with-motionbuilder-python\/","url_meta":{"origin":104,"position":5},"title":"How to use functions with MotionBuilder Python","author":"admin","date":"April 25, 2017","format":false,"excerpt":"Using functions will save you from re-writing and maintaining many of the same lines of code over and over. What is a Python Function? \"A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and\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\/c2c827b3a6ea16d024b6875b5610651c-e1493127532666.gif?fit=251%2C300&resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/104"}],"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=104"}],"version-history":[{"count":16,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":684,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions\/684"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media\/141"}],"wp:attachment":[{"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vicdebaie.com\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}