PyMel on OSX

So I’m attempting to use PyMel to write a layout, however, I keep running into this issue. When I use:

import pymel as pm

and then try to run anything with pm it fails. For example:


pm.sphere()
# Error: 'module' object has no attribute 'sphere'
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
# AttributeError: 'module' object has no attribute 'sphere' # 

or:


testWindow = pm.window()
testWindow.setTitle('Carlos Mencia')
pm.menuBarLayout()
pm.menu(label='Test')
pm.menuItem(label='Things')
pm.columnLayout('testColumn', adjustableColumn=0, rowSpacing=5, parent=testWindow)
pm.button(label='Stuff')
pm.textScrollList('testScrollList', allowMultiSelection=1, height=145, width=250, e=1, ra=1, parent=testWindow)
pm.showWindow(testWindow)

I’m using the newest version of PyMel in 2011 and I’ve tried it in 2012 with the stock PyMel and I get the same thing. (I was watching south park and carlos mencia was on it so that’s why I named my window it. Plus I get to delete it, which is great. :D: )

I’ve tried it with import pymel.core as pm and it works fine, but I’m curious as to why it’s not working because it seems like there’s an obvious issue. Thanks!

—Edit—
Ok. Ignore this. Thanks to Seth (djTomServo) he pointed out that I should be using import pymel.core or import pymel.all. :slight_smile:

So as to not waste the thread, I’m having an issue with my UI and PyMel anyhow. Here’s my code:


import pymel.all as pm

def main():
    """docstring for main"""

    def doThat(aString):
        print 'Did that...'
    
    def doThis(bString):
        pm.textScrollList('testScrollList', e=True, append='Did This')
    
    def clearIt():
        pass

    try:
        pm.deleteUI(testWindow)
    except:
        pass
        
    # Create our UI
    testWindow = pm.window()
    testWindow.setTitle('Carlos Mencia')
    pm.menuBarLayout()
    pm.menu(label='Test')
    pm.menuItem(label='that', command=doThat)
    pm.columnLayout('testColumn', adjustableColumn=0, rowSpacing=5, parent=testWindow)
    pm.button(label='this', command=doThis)
    pm.textScrollList('testScrollList', allowMultiSelection=1, height=145, width=250, e=True, ra=True, parent=testWindow)
    pm.showWindow(testWindow)


        
if __name__ == '__main__':
    main()

But I keep getting this error:


# Error: line 1: Object 'testScrollList' not found.
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "/Users/johnneumann/Library/Preferences/Autodesk/maya/2011-x64/scripts/myScripts/python_testing.py", line 62, in main
#     pm.textScrollList('testScrollList', allowMultiSelection=1, height=145, width=250, e=True, ra=True, parent=testWindow)
#   File "/Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/pymel-1.0.0-py2.6.egg/pymel/internal/factories.py", line 639, in newUiFunc
#     return beforeUiFunc(*args, **kwargs)
#   File "/Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/pymel-1.0.0-py2.6.egg/pymel/internal/factories.py", line 792, in simpleWrapFunc
#     res = beforeSimpleWrap(*args, **kwargs)
#   File "/Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/pymel-1.0.0-py2.6.egg/pymel/internal/factories.py", line 756, in newFuncWithReturnFunc
#     res = beforeReturnFunc(*args, **kwargs)
#   File "/Applications/Autodesk/maya2011/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/pymel-1.0.0-py2.6.egg/pymel/internal/pmcmds.py", line 98, in wrappedCmd
#     res = new_cmd(*new_args, **new_kwargs)
# RuntimeError: Object 'testScrollList' not found. # 

This is my first foray into using PyMel so if I’m just an idiot and missed something simple, go ahead and throw that out there. :slight_smile: Thanks for the help.

—Edit—
Ok so again Seth came to my rescue. I just needed to remove the e=True within the creation of my textScrollList and then I figured out I had it parented incorrectly. :slight_smile: No more replies to save the thread. :wink: THANKS SETH!

This ought to work

import pymel.all as pm
        
def main():
    """docstring for main"""

    def doThat(aString):
        print 'Did that...'
        
    def doThis(*args):
        pm.textScrollList(tsl, e=True, ra=True, append='Did This')
    
    def clearIt():
        pass

    try:
        pm.deleteUI(testWindow)
    except:
        pass
        
    # Create our UI
    testWindow = pm.window()
    testWindow.setTitle('Carlos Mencia')
    pm.menuBarLayout()
    pm.menu(label='Test')
    pm.menuItem(label='that', command=doThat)
    pm.columnLayout('testColumn', adjustableColumn=0, rowSpacing=5, parent=testWindow)
    pm.button(label='this', command=doThis)
    tsl = pm.textScrollList(allowMultiSelection=1, height=145, width=250)
    pm.showWindow(testWindow)


        
if __name__ == '__main__':
    main()

Ok now that’s starting to help me make sense of it all. And I don’t know why I didn’t use *args in the first place. Thanks a lot. I think I’m getting how this all works now. :slight_smile: