Here's another way to read weights. Not sure if it's faster. Probably not.
xsi = Application
obj = xsi.Selection(0)
envCls = obj.ActivePrimitive.Geometry.Clusters(0)
envProp = envCls.Properties(0)
# Envelope ICE attrs:# EnvelopeWeights, EnvelopeWeightsPerDeformer,
EnvelopeDeformerIndices, NbDeformers
data = envProp.GetICEAttributeFromName("EnvelopeWeights").DataArray2D
indices = envProp.GetICEAttributeFromName("EnvelopeDeformerIndices").DataArray2D
nbdef = envProp.GetICEAttributeFromName("NbDeformers").DataArray[0]print
"Deformer count: %s" % nbdef
for i,val in enumerate(zip(indices, data)):
idx, val = val
print "Point #%s indices:(%s) - values:(%s)" % (i,idx,val)
Beware that letting it print everything may be a terrible idea with a lot
of points. :p May wanna put in a "if i > 100: break" line in there.
On Fri, May 31, 2013 at 10:50 AM, Martin <[email protected]> wrote:
> Have you tried VBScript?
> I usually do my envelope related scripts in VBScript because it is way
> faster than JScript (my main scripting language).
>
> VBScript
> selection(0).Envelopes(0).Weights.Array
>
> is faster than
>
> JScript
> new VBArray( selection(0).Envelopes(0).Weights.Array )
>
> and way way more faster than
>
> JScript
> selection(0).envelopes(0).Weights.Array.toArray()
>
> I don't use Python, but in my tests, Python has been the slowest of the
> three when dealing with envelopes, subcomponent arrays and a bunch of loops.
>
> M.Yara
>
>
> On Fri, May 31, 2013 at 10:29 PM, Eric Thivierge
> <[email protected]>wrote:
>
>> 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....
>>
>>
>>
>