How to subtract a list from a list inPython?

It dawned on me today:  I’ll add lists on a regular basis (listC = listA + listB), but I don’t think I’ve ever ‘subtracted’ listA form listB.  A quick search didn’t come up with much (but I know it’s out there).  I came up with this method using list comprehensions:

listA = ["a","b"]
listB = ["b", "c"]
listC = [item for item in listB if item not in listA]
print listC
# ['c']

But there’s got to be an easier method?  Maybe using sets?

Posted on my Python Wiki too.

Centering joints in edge loops

When I’m rigging, I will often create an initial ‘rig-skeleton’ that fits inside the mesh to be deformed. To speed things along, I first just rough in the joint positions by snapping them to verts.   But later I like to get them centered into a selection of verts, and usually that selection is some form of edge loop.

I wrote some mel that does this:

  • You pick a joint, and an edge on a mesh
  • The code detects the joint, and the edge
  • Based on the edge, find the edge loop
  • Convert the edge loop into a selection of verts
  • Find the average position of all the verts
  • Move the joint pivots to this new position
  • Reselect the joint, and the new vert selection.

You can find the mel code over on my Mel Wiki.

Updated ‘Processing Sketches’ page

One of the main reasons I wanted to make my own site was to get my Processing sketches up online.  Success!  I’m just starting to upload them, and they are now accessable via the ‘Processing Sketches‘ menu drop-down.  Over time I’ll be updating these sub-pages with the stuff I’ve worked on, and am working on.

I’ve made the switchover…

I finally feel comfortable enough in WordPress that I have officially discontinued my old blog over at Blogger: (although it’s still around of course)

At some point I’ll try and figure out how to import the old posts  over here, but in the meantime, long live WordPress! :)

Auto Joint Orientations in Maya

I have this pet peeve:  Whenever I create joint hierarchies in Maya, it will automatically setup the joint orientation value for you (based on option set in the ‘Joint Tool’ tool settings).  That, is handy.  However, the last joint in the chain isn’t auto-oriented:   A joint’s auto-orientation is based on the vector between it, and its child.  So obviously, the last joint in the chain has no child, so it can’t use this system.  The result is, the last joint is always oriented to the worldspace global axis.  Which is almost exactly never what I want.

The workaround is easy, just make a little script to process all the joints in a selected hierarchy.  But it sure would be nice if they had an option to do this automatically in the UI….

Eric Pavey - 2008-12-19
For the selected hierarchies, zero the joint orient values
on all leaf joints
# Python code
import maya.cmds as mc

kids = mc.listRelatives(, children=True, type="joint", allDescendents=True)
for k in kids:
    if mc.listRelatives(k, children=True, type="joint") is None:
        for attr in [".jointOrientX", ".jointOrientY", ".jointOrientZ"]:
            mc.setAttr(k+attr, 0)
        print "Zeroed '" + k + ".jointOrient'"