scSaveWeights for export/importing skinCluster weights in Maya

I have written an useful Maya python API plugin which exports out weights from polygon mesh or vertices to text file(optionally binary),Which can be used later.
This process is mostly useful when User wish to change position of joints in a rig with skinCluster , or just want to update rig file with latest weights from other file.
I have in past used Michael comets famous Mel script cometSaveWeights, which works great but is very slow when importing weights on dense mesh.

It was my first attempt at writing something in Maya API. Attached in plugin which I have tested on Maya 2008 to 2011.

Mel Command to export weights
scSaveWeights -roundOff 5 -action “export” -file “d:/weights.txt”;

Mel Command to import weights
scSaveWeights -action “import” -file “d:/weights.txt;


Go to windows>Settings/prefrence > plug-in manager and browse to the
I would suggest to open the py file in IDE and read through comments in the beginning of  script.

Exporting weights on polygon mesh with vertex count 12432 skinned with 255 joints took 7.6378 seconds
whereas Importing took 66.3445147672 seconds and in quick mode it takes 19.937 seconds while exporting
and takes 7.5559 seconds while importing.

Importing weights with cometSaveWeights.mel took more than 7 minutes on same Mesh. 

edit: updated script to work with selected polygon object and in component mode, while importing weights.

Discovering PyMEL

Yes, i was the one who used to love mel like anything. I think i still do for its simplicity inside maya,
but it was time to move on..

I haven’t looked much around in other 3d packages but everyone was saying python is way foward.
I used python inside maya and find it pretty boring cluttered repetitive compared to MEL
(apart from standard python librarypython inside maya has nothing to offer).

And then about year pass by i was member of Google group PYTHON_INSIDE_MAYA they were developing PyMEL
guy named Chad Dombrova actually cook this whole new concept of pythonic way to look inside maya.

I gave PyMEL shot about a month back i installed release 0.9.1 and i was completely hooked. Before i go further i must say
I think PyMel is way forward to do scripting and programming inside maya (the python way). I also think there are some tiny miny glitches
here and there inside PyMEL which may prevent you from migrating, but with so many talented people collaborating i don’t think there would be
much problem once the final build is released.

Maya commands the PyMEL way:

mel code :

getAttr “pPlane1.translateX”


>>> plane = polyPlane(n=’myPlane’)
>>> plane.translateX.get()


>>> plane.translateX.set(10.0)

Basically what PyMEL does is it attaches attributes directly to object (PyNode) and then we can play with those attributes and properties (Methods)
It is whole OOPS based system with classes and all those modern language terminologies put into practice. With objects inheriting properties from
parent classes like “joint” inheriting from “transform” and all