I am assuming that you set:
self.throwAwayWeights to a OpenMaya.MDoubleArray() to capture the skinCluster weights at some point.

Since each time you capture the old weights it over write the weights so they will all point to the weight (The last weight)
If you create a new OpenMaya.MDoubleArray() on each iteration that it will prevent a list of the same weights.

Here is the exert of my code for the undo creation array only:

while not toNode.MItGeometry.isDone():
 oldWeight = OpenMaya.MDoubleArray()
 ...
 toNode.skinCluster.setWeights (toNode.MDagPath, toNode.MItGeometry.currentItem(), iIndices, newWeights, True, oldWeight )
 toNode.oldWeights.append(oldWeight)

Since I recreated oldWeight on each iteration, toNode.oldWeights kept from pointing to the same MDoubleArray.

When I set the skinCluster back to its orginal weights with undo, I omitted the last argument, oldWeight.

As for you indicies problem.. here is an exact exert of my code:
iIndices = OpenMaya.MIntArray()
for i in range( toNode.influenceObjects.length() ):
 iIndices.append(i)

Don't see the probem with your version. How ever I was able to recreate the problem without touch the iIndices.

I changed:
oldWeight = OpenMaya.MDoubleArray()
to:
oldWeight = []

I got the following error:
# TypeError: in method 'MFnSkinCluster_setWeights', argument 4 of type 'unsigned int' #

So, the problem with yours is somewhere else. Make sure that each argument is created correctly.

Hope that helps,
-brian
www.meljunky.com

-------- Original Message --------
Subject: [Maya-Python] Re: MFnSkinCluster.setWeights doesn't work from
multiple weights at once.
From: Brandon Harris <[email protected]>
Date: Thu, November 05, 2009 5:36 pm
To: python_inside_maya <[email protected]>


OK. I felt it was appropriate to post my issue here because it falls
inline with this issue.

j=0
while not compItr.isDone():
self.tmpOldSkinWeights = []
self.skinCluster.setWeights(self.relatedShape,compItr.currentItem
(),self.infIndices,self.newWeightsArray,True,self.throwAwayWeights)
for i in xrange(self.throwAwayWeights.length()):
self.tmpOldSkinWeights.append(self.throwAwayWeights[i])
self.oldSkinWeights.insert(j, self.tmpOldSkinWeights)
j = j+1
compItr.next()

OK. so first off, this works exactly the way that I want it to. It
takes the new weights and applies them to the proper components. Now
because I'm iterating over the components and the old weights that are
returned are overwritten with each pass, I have elected to catch the
values and put them into a list of lists so I can use them for Undos.
So when I undo I want this to happen.

compItr = openMaya.MItGeometry(self.objectPath, self.objectComps)
i = 0
while not compItr.isDone():
self.skinCluster.setWeights(self.relatedShape,compItr.currentItem
(),self.infIndices,self.oldSkinWeights[i],True,self.throwAwayWeights)
print self.oldSkinWeights[i]
i = i+1
compItr.next()

Now this is basically an exact mirror of the first part that works
correctly (as far as I know) but when used during the Undo it throw
this error.

// Error: line 1: in method 'MFnSkinCluster_setWeights', argument 4 of
type 'unsigned int'
# Traceback (most recent call last):
# File "/data/film/apps/reelfx/maya/plug-ins/linux/2009-x64/
TestCommand.py", line 189, in undoIt
# self.skinCluster.setWeights(self.relatedShape,compItr.currentItem
(),self.infIndices,self.oldSkinWeights[i],True,self.throwAwayWeights)
# TypeError: in method 'MFnSkinCluster_setWeights', argument 4 of type
'unsigned int' //


Also, for my self.infIndices I am doing this.

self.infIndices = openMaya.MIntArray()
for i in xrange(self.skinInfluences.length()):
self.infIndices.append(i)

Hopefully my tabbing hasn't gotten too bad with copying it over here,
but hopefully you get an idea for what I'm doing. It's the same error
meljunky was having, but it works fine unless I'm undoing. thanks in
advance!

Brandon L. Harris




--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to