Monday, May 20, 2013

Python properties and motionbuilder

I'm sure there are already a bunch of good tutorials on how to use properties and decorators, but I rarely used this before, so I'm also sharing this to just wrap my head around it once more.
I am in the middle of writing Py-Mel'ish libraries for motionbuilder and propertys are making my life a lot easier. They will essentially help you reducing your production code later almost by half and make it much more readable.

To get the startframe of the animationrange in motionbuilder you have to do something like this: There is no need to argue that this is just horrible...
Ok, how about setting it? No, its not this

Lets try to unify that! There might be similar things we want to do, like get and set the current frame. So let's decide on writing a small timeline class and add a few functions to that.
The functions we will write here, are getter and setter functions. To make a function a getter, you basically add a property-decorator in front of your function.

The setter function is defined like this getter-functionname.setter.
Make sure that this following function has the same name as the getter function.

Take a look at the code example here:

 Now we just have to instanciate the class To get the animationrange we just have to do this now And we set it like this The same goes for the currentframe, to get it we call And to set it

So to recap, properties give you the ability to execute different functions depending on wether you set or get them.


  1. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    Python Training in Bangalore

  2. Cognex is the best institute in Chennai to learn aws, microsoft azure, prince2 foundation, ITI V4 foundation, etc. Cognex is the AWS Training in Chennai

  3. Dr. Vivek Galani is a leading expert in skin and hair. At hair transplant clinic in Surat Skin Care, Cosmetic Laser, Hair Transplant & Slimming Center, Dr. Galani offers the most advanced cosmetic and dermatologic care treatments. The clinic uses advanced FUE methods to produce high-quality hair transplants.

  4. Shreeja Health Care is leading manufacturer of Oil Making Machine. Shreeja Oil Extraction Machine is able to extractoil from various seeds like peanuts, Coconut, Sesame, Soybean, macadamia nuts, walnuts, sunflower seeds, vegetable seeds flaxseed et.

  5. Thanks for posting the best information and the blog is very helpful.python course in Bangalore