Search code examples
dialogmayapymel

Using fileDialog2 to open files in Maya


In the documentation for fileDialog2 (http://download.autodesk.com/us/maya/2011help/pymel/generated/functions/pymel.core.system/pymel.core.system.fileDialog2.html), it says acceptMode (am) can be set to 0 or 1 to tell it if it should be opening or saving images.

However, upon setting this to 0 or 1, nothing actually happens and None is returned, and just leaving it empty will result in save dialog box. I'm currently using fileDialog to get around the problem, but it's an earlier version without as much functionality, and when one newer function should cover both, it seems pointless having to use an old one at the same time.

Here's a quick example of what to do:

import pymel.core as pm

pm.fileDialog2()
#brings up a save file window

pm.fileDialog2( am = 1 )
pm.fileDialog2( acceptMode = 0 )
#nothing happens

Also, using help(pm.fileDialog2) just comes up with help for NoneType or list depending on if a file is selected or not.


Solution

  • You need to specify the fileMode option:

    import pymel.core as pm
    test = pm.fileDialog2(fileMode=1)
    print test