Have you tried a GridData object? It would abstract the problem away from
Python and be flexible enough to pass around between commands written in
various languages. I usually use the GridData object because it simplifies
coding and has a few methods specifically for working with column data making
it easier to manipulate weight values per deformer. You do give up some speed
compared to other available methods in the other languages, but in your
situation the GridData might perform faster than anything available in Python.
The snippet below runs in Jscript in about 4 seconds on my 5-year old computer.
Will probably run faster on yours.
// JScript
function main()
{
var oObject = Selection(0);
var oEnvelope = oObject.Envelopes(0);
// Get weight values from envelope
var oWeightData = XSIFactory.CreateGridData();
oWeightData.Data = oEnvelope.Weights.Array;
// Modify the weight values for the first deformer
var aWeightValues = new Array( oEnvelope.Weights.Count );
oWeightData.SetColumnValues( 0, aWeightValues );
// Update the envelope with modified weight values
oEnvelope.Weights.Array = oWeightData.Data;
}
From: [email protected]
[mailto:[email protected]] On Behalf Of Eric Thivierge
Sent: Friday, May 31, 2013 6:29 AM
To: [email protected]
Subject: Re: Slow Reading / Writing Envelope.Weights.Array
This takes even longer ~ 14 seconds. I really seems the slowness is simply
accessing envelopeOp.Weights.Array.
Any devs paying attention that could confirm that this is just a slow call?
Would doing these operations in C++ be the only way to speed them up?
# Python
# =============================================
from platform import system as OStype
from time import clock
xsi = Application
log = xsi.LogMessage
sel = xsi.Selection
start_time = clock()
envelopeOp = sel(0).Envelopes(0)
weightsTuple = envelopeOp.Weights.Array
weights = [weightsTuple[j][i] for i in xrange(len(weightsTuple[0])) for j in
xrange(len(weightsTuple))]
timeTaken = clock() - start_time
units = ["seconds" if OStype() is "Windows" else "milliseconds"][0]
msg = "It took "+str(timeTaken)+" "+units+" to process your code."
log(msg)
# =============================================
Eric Thivierge
===============
Character TD / RnD
Hybride Technologies
On 31/05/2013 3:00 AM, Bartosz Opatowiecki wrote:
Also:
def getWeights(envelopeOp):
weightsTuple = envelopeOp.Weights.Array
return [weightsTuple[j][i] for i in range(len(weightsTuple[0])) for j in
range(len(weightsTuple))]
xrange should be more efficient than range....