On Thu, May 13, 2010 at 6:45 AM, PixelMuncher <[email protected]> wrote:
> Using Amorano's code, I was able to finish my joint weight locking
> tool with PyMEL code.
>
> For me, the biggest lesson here has been referencing objects as
> strings.
> What I still find confusing is:
>
> print tmpJnts
> [nt.Joint(u'joint1'), nt.Joint(u'joint2'), nt.Joint(u'joint3'),
> nt.Joint(u'joint4'), nt.Joint(u'joint5')] #List of objects
> print tmpJnts[0]
> #joint1 - This is the name of the joint, but it is still an object,
> not a string
>
> Why doesn't:
> print tmpJnts[0]
> return:
> nt.Joint(u'joint1')
>
>
All objects in pymel have 2 string representations - their str and repr.
The first (str) is intended to be more readable, the second (repr) is
intended to be more useful 'programatically' - ideally, you would be able
to do eval(repr(someObject)) and get back something equivalent to
someObject.
When you print something, you always get the str version - ie,
print something
is essentially the same as
print str(something)
With most python interpreters, when you evaluate an object by itself, what
is printed out is the repr of that object - so if you just evaluate:
PyNode('joint1')
you would get
nt.Joint(u'joint1')
Unfortunately, prior to maya2011, this was not the case - it would still
return the str representation. To get the repr there, you have to invoke
repr manually:
repr(PyNode('joint1'))
Finally, a shorthand for repr is to enclose the item in backticks - so
repr(something)
is equivalent to
`something`
Paul:
> I was able to cast a string as an object using PyNode, but "Transform"
> and "Joint" threw errors:
> print PyNode( jntSplitList[0]).name() # Works
> print Joint( jntSplitList[0]).name()
> # Error: NameError: file <maya console> line 1: name 'Joint' is not
> defined #
>
>
Ah, my mistake - all the node classes, other than the basic ones (PyNode,
Attribute, Component) are in their own module, to avoid cluttering up the
main pymel.core namespace - pymel.core.nodetypes, also available from the
pymel.core namespace as nt - this is what the 'nt' in
nt.Joint(u'joint1')
is for.
- Paul
--
http://groups.google.com/group/python_inside_maya