import pymel.core as pm
tmpJnts = pm.ls(sl=1)
numJnts = len(tmpJnts)
print tmpJnts
print tmpJnts[1].name()
jntStringList = ' '.join([j.name() for j in tmpJnts])
print jntStringList
jntSplitList = jntStringList.split (' ')
print len(jntSplitList)
jointsRebuilt = [pm.PyNode(j) for j in jntSplitList]
print jointsRebuilt
for j in jointsRebuilt:
print j.name()
Works great ;p
On May 12, 9:44 am, PixelMuncher <[email protected]> wrote:
> Thanks for the help guys.
> After a couple more hours exploring this, I've tried everything I can
> think of, but I'm still not getting it.
> Probably missing some small thing:
>
> tmpJnts = ls (sl = 1)
>
> numJnts = len(tmpJnts)
> print tmpJnts
> [nt.Joint(u'joint1'), nt.Joint(u'joint2'), nt.Joint(u'joint3'),
> nt.Joint(u'joint4'), nt.Joint(u'joint5')]
>
> print tmpJnts.name() # Fails - 'list' object has no attribute
> 'name' (I get that)
> print tmpJnts[0].name() # Works
>
> # Copy joints to space separated list - avoid adding a trailing space:
> jntStringList = ''
> count = 1
> for jnt in tmpJnts:
> if count < numJnts:
> jntStringList += jnt.name() + ' '
> else:
> print ('else add jnt')
> jntStringList += jnt.name()
> count += 1
>
> print jntStringList
> # joint1 joint2 joint3 joint4 joint5
> print jntStringList[0]
> # j (First Letter)
> print jntStringList[0].name() #Fails because it is text object
> ('unicode' object has no attribute 'name') (I get that)
>
> jntSplitList = jntStringList.split (' ')
> print len(jntSplitList)
> print jntSplitList
> [u'joint1', u'joint2', u'joint3', u'joint4', u'joint5']
> print jntSplitList[0]
> #joint1
> select (jntSplitList[0]) #Works because select is a Maya command which
> takes text as arg -
>
> # After converstion to a list and back, the attr method fails because
> the object is text - "it's got no maya special goodness"
> print jntSplitList[0].name() #Fails - 'unicode' object has no
> attribute 'name' (I get that)
>
> #--------------------------------
> HERE'S THE PROBLEM:
> #--------------------------------
> #cast strings back to pymel objects:
> print Attribute(jntSplitList[0]).name() # Fails - Determined type is
> Joint, which is not a subclass of desired type Attribute
>
> if Attribute(jntSplitList[0]).hasAttr('liw'):
> print ('Has Attr')
> # Fails - Determined type is Joint, which is not a subclass of desired
> type Attribute
>
> for jnt in jntSplitList:
> myNode = PyNode(jnt)
> if jnt.hasAttr('liw'):
> print ('Has Attr')
> # Error: AttributeError: file <maya console> line 3: 'unicode' object
> has no attribute 'hasAttr' #
>
> #------------------------------------------------
> #------------------------------------------------
> Also, trying to use the name() method to build the string list failed:
> #------------------------------------------------
> tmpJnts = ls (sl = 1)
>
> # Copy joints to space separated list:
> jntStringList = ''
> jntStringList = tmpJnts[0].name
> print jntStringList
> <bound method Joint.name of nt.Joint(u'joint1')>
>
> print len(jntStringList)
> # Error: TypeError: file <maya console> line 1: object of type
> 'instancemethod' has no len() #
>
> jntStringList = ''
> jntStringList += str(tmpJnts[0].name)
> <bound method Joint.name of nt.Joint(u'joint1')>
> print len(jntStringList)
> 48
>
> --http://groups.google.com/group/python_inside_maya
--
http://groups.google.com/group/python_inside_maya