ECToo / pymel

Automatically exported from code.google.com/p/pymel
0 stars 0 forks source link

cannot set multi attribute #149

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
i tried to set a whole multi attribute in a single row
and i was given an error

maya 2009x64
pymel 0.9.1

i skinned a 1538 vtx mesh with 9 joints
and i tried this:

sk=PyNode('skinCluster1')
zero=[0 for x in xrange(9)]
for k in xrange(1538):
  sk.wl[k].w.set(zero)

# Error: The attribute 'skinCluster1.weightList[0].weights' is a multi. Its
values must be set individually.
# Traceback (most recent call last):
#   File "<maya console>", line 3, in <module>
#   File
"D:\gfx\Autodesk\Maya2009\Python\lib\site-packages\pymel-0.9.1-py2.5.egg\pymel\c
ore\general.py",
line 418, in setAttr
#     cmds.setAttr( attr, *args, **kwargs)
#   File
"D:\gfx\Autodesk\Maya2009\Python\lib\site-packages\pymel-0.9.1-py2.5.egg\pymel\c
ore\pmcmds.py",
line 96, in wrappedCmd
#     res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: The attribute 'skinCluster1.weightList[0].weights' is a
multi. Its values must be set individually.

it's possible with the setAttr command with mel
so why not with pymel ?

Original issue reported on code.google.com by wou...@gmail.com on 17 Jan 2010 at 3:46

GoogleCodeExporter commented 9 years ago
hi, can you provide the above pymel example translated into maya.cmds so i can 
see 
the difference?  it's also useful to provide some code on how you generated the 
'skinCluster1' node. it just makes our lives a bit easier.

Original comment by chad...@gmail.com on 2 Feb 2010 at 7:14

GoogleCodeExporter commented 9 years ago
i'm sorry ! i wasn't really sure about this error so it was a bit confusing
thanks to pymel now i have a good understanding how multi attrs works in maya 
with
indices

from pymel.core import *

p=polyCube()
select(cl=1)
j1=joint(p=[-1,0,0])
j2=joint(p=[1,0,0])
select(p,j1,j2)
sk=skinCluster()[0]

so you have this polycube skinned with 2 joints

the mel that works:

string $sk="skinCluster1";
for($k=0; $k<8; $k++) {
 setAttr ($sk+".wl["+$k+"].w[0:1]") 0 0;
}

the pymel that doesn't work

sk=PyNode('skinCluster1')
zero=[0 for x in xrange(2)]
for k in xrange(8):
  sk.wl[k].w[0:7].set(zero)

it is providing slice to setAttr that fails
i don't know python enough to know if you can fix that but it could be 
interesting

at first i thought you could send directly a list to the multi attribute like 
that:
multiAttribute.set(list)
but maya mel brings the same error if you do that and you have to provide the 
slice
to set before

Original comment by wou...@gmail.com on 2 Feb 2010 at 2:24

GoogleCodeExporter commented 9 years ago
btw here is the cmds version that works ;)
i just remembered that i forgot to write it

for k in xrange(8):
 cmds.setAttr('skinCluster1.wl[%s].w[0:1]'%k, 0, 0)

Original comment by wou...@gmail.com on 5 Feb 2010 at 12:26

GoogleCodeExporter commented 9 years ago
the pymel attributes currently don't support slicing, or assigning to multiple 
elements at once.

Would be nice to get this working, though, so I'm going to mark this as an 
enhancement, and hopefully we'll be able to get to it...

Original comment by elron...@gmail.com on 21 Jan 2011 at 4:41