Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, May 30, 2012

MasterClass Binder Module updated

Thought I'd share an update to the MasterClass AnimationBinder.py as requested by a friend who was having problems binding up a Quadruped. In the original file that I shipped with the MasterClass there was a call for making the AimBinder node that I show in the class but I never added it to UI call. So this new file has a button, "AimBinder" that builds the complex AimBind for you in one go.

This button call expects 3 nodes selected. The first is the node that you want the bind to aim at, the second is the Controller on the rig you want to drive and the third becomes the parent to the bindNode itself as well as being used to parent an UpVector locator to stop the aim from spinning. Its basically the node as I build manually in the video.

updated AnimationBinder.py

cheers

Mark

Thursday, November 24, 2011

Python, shit what did we do before it????

So I've been playing with some string formatting for one of our legacy UI's which is basically just a textScroller that gets filled in a loop with all the export Tag information for the current scene, but I wanted to line up the data nicely. In mel this was just horrible but Python..... 1 line!

The format calls on strings are just fabulous, if you've not taken a look at them them I recommend you do so, here's the Python docs that relate to them:

http://docs.python.org/library/string.html

So in the example here we have some string data that we want to carefully format. We want to make sure each entry in the line is the same length and some of them want to be left, right or center justified.

this='This is'
nice='nicely'
form='formatted'
data='data'

print '{this:.<15}:{nice:_^12}:{form:<20}:{data:>7}'.format(\
        this=this,nice=nice,form=form,data=data)

#This is........:___nicely___:formatted           :   data
So :
{this:.<15}

The above tells the format to replace the key 'this' with the passed in arg, then the '.<' tells it that it's left justified and any gaps should be replaced with '.' finally the number after it is the length to pad the data out to.
Similarly the '_^12' is formatting to center justify and adding '_' to the padding. Now that line fed to a loop thats filling the textScroll with scene data formats and lines everything up (as long as you set the fontType to the scroll to be fixedWidth that is)

Now that in Mel was the length of this blog!

Tuesday, October 25, 2011

MasterClass finally on Vimeo

Finally added the MasterClass to Vimeo for you all to enjoy... thanks for watching!
Autodesk MasterClass - Live Animation Binding from Mark Jackson on Vimeo.
Don't forget the Toolkit link below

Wednesday, October 19, 2011

MasterClass - New Maya cmds compatible version

After a number of requests I've gone through the MasterClass toolkit and made it backward compatible with Maya 2008 onwards (actually I've only run it back to 2009 but should still work on 2008). This is kind of tested but if you get any issues let me know and I'll fix them. Basically all I've done is to remove the PyMel calls and replace them with cmds, also made it Python 2.5 compliant.

Anyway, here's the link to the new AnimationBinderCmds.py module file. Install is easy, like the main class all you do is drop it into the Maya scripts folder, or any folder on the Maya scripts path, then in a Python Tab type: (with no tabs or spaces at the front of each line)

import AnimationBinderCmds as AB
AB.AnimBinderUI.Show()

Here's the link:


AnimationBinderCmds.py


Thanks for the interest

Mark

Thursday, August 18, 2011

Maya Command Completion issues in Python

Something Dave discovered a while ago and has just come back to bite us again is that the dot code completion in the scriptEditor in Maya is actually RUNNING the code inside Python property blocks when you call a dot complete (Ctrl+Space). It's not just returning the function/property list by using something like the inspect module, but actually running the property itself. The same is true when
you hit return to accept and fill that function/property in the script editor.

Test it, add this in a Python Script window:

import pymel.core as pCore

class AutoCompleteTest(object):

    def __init__(self):
        pass

    @property
    def Test(self):
        print "Im being CALLED Multiple times!!!!!\n" 
        pCore.newFile(force=True)


Now do the following:

com=AutoCompleteTest()

turn on ’Command Completion’ and do a dot complete to inspect the com object you just made!

The property is now being RUN. So what you ask? Well lets say you are doing something stupid like the fileNew example above, just by trying to get code completion you've actually nuked your scene. Also because it's doing this for all the inspect calls it means that it's running all code, in all property blocks which makes it very, very slow!

Mark


Friday, March 4, 2011

Nice Python function for dictionaries

Not my code but found this whilst browsing for some functionality. Basically allows you to use .dot formatting when accessing keys in a dict:


class dotdictify(dict):
    marker = object()
    def __init__(self, value=None):
        if value is None:
            pass
        elif isinstance(value, dict):
            for key in value:
                self.__setitem__(key, value[key])
        else:
            raise TypeError, 'expected dict'

    def __setitem__(self, key, value):
        if isinstance(value, dict) and not isinstance(value, dotdictify):
            value = dotdictify(value)
        dict.__setitem__(self, key, value)

    def __getitem__(self, key):
        found = self.get(key, dotdictify.marker)
        if found is dotdictify.marker:
            found = dotdictify()
            dict.__setitem__(self, key, found)
        return found

    __setattr__ = __setitem__
    __getattr__ = __getitem__



Now we can use '.' rather than having to use standard ['key'] syntax: eg:

life = {'bigBang' :  {'stars':  {'planets': {} }}}

life = dotdictify(life)

print life.bigBang.stars.planets
instead of:
print life['bigBang']['stars']['planets']

life.bigBang.stars.planets.earth = { 'singleCellLife' : {} }
print life.bigBang.stars.planets

Ok, so it's just syntax candy, but does makes things easier to read in code.

Monday, September 6, 2010

fileBrowserDialog is no more! Thankyou Pymel!

Anybody who's used the Maya fileBrowserDialog command will know what a pain in the arse it is, having to always pass in a function for it to use on the returned selection. Why the hell couldn't it just give you back the path.
import pymel.core as pCore
print 'Folder Selected : %s' % (pCore.promptForFolder())
import pymel.core as pCore
print 'File Selected : %s' % (pCore.promptForPath())
Well, no more, I might have guessed that Chad would have simplified this and bingo Pymel promptForFolder() and promptForPath() functions. At last, it opens the file prompt window and just gives you back the return.

Chad,Pymel thankyou!