LumaPictures / pymel

Python in Maya Done Right
Other
479 stars 130 forks source link

setAttr on floatArray data type does not work as expected #421

Open ParticlePeter opened 5 years ago

ParticlePeter commented 5 years ago

When using setAttr on a floatArray data type attribute, the attribute data gets "corrupted". See example bellow: A 3 element floatArray created and initialized through maya.cmds, returns only one element (the first) after updated through PyMel. Resetting the attribute through maya.cmds.setAttr "un-corrupts" the attribute data again, but this is not shown in the example to keep it brief. Seems to be a rarely used corner case, as setAttr on doubleArray data type works just fine. Maya version 20180400, PyMel version 1.0.10.

import maya.cmds as mc
import pymel.core as pm

mc.createNode( 'locator', n='node' )
mc.addAttr(ln='dArray', sn='da', dt='doubleArray')
mc.addAttr(ln='fArray', sn='fa', dt='floatArray')

print 'mc.setAttr type doubleArray'
mc.setAttr("node.dArray", (2, 3.14159, 2.782), type="doubleArray")
print 'mc.getAttr : {0}'.format(mc.getAttr("node.dArray"))
print 'pm.getAttr : {0}'.format(pm.getAttr("node.dArray"))
print

print 'mc.setAttr type floatArray'
mc.setAttr("node.fArray", (2, 3.14159, 2.782), type="floatArray")
print 'mc.getAttr : {0}'.format(mc.getAttr("node.fArray"))
print 'pm.getAttr : {0}'.format(pm.getAttr("node.fArray"))
print

print 'pm.setAttr type doubleArray'
pm.setAttr("node.dArray", (1.0, 2.0, 3.0), type="doubleArray")
print 'mc.getAttr : {0}'.format(mc.getAttr("node.dArray"))
print 'pm.getAttr : {0}'.format(pm.getAttr("node.dArray"))
print

print 'pm.setAttr type floatArray'
pm.setAttr("node.fArray", (1.0, 2.0, 3.0), type="floatArray")
print 'mc.getAttr : {0}'.format(mc.getAttr("node.fArray"))    # Returns a list with one element
print 'pm.getAttr : {0}'.format(pm.getAttr("node.fArray"))    # Returns a list with one element
print