Check for unsaved changes in pymel

How do you check for unsaved changes in pymel? In the maya cmds it’s via the file-command:

import maya.cmds as cmds
print cmds.file(q=True, modified=True)

But “file” is not defined in pymel

import pymel.core
print pymel.core.file(q=True, modified=True)
// Error: 'module' object has no attribute 'file'
# Traceback (most recent call last):
#   File "<maya console>", line 3, in <module>
# AttributeError: 'module' object has no attribute 'file' //

Which makes sense, as pymel aims to be more “pythonesque”. But i haven’t found any replacement functionality for the “modified”-flag yet, neither in the pymel docs, nor via google. Has anyone more info?

I think the best option currently is to just fall back to cmds.file(query=True, modified=True)
I’ve opened a pull request to add an isModified function to pymel, but no clue if or when that might get accepted and pushed out to users.

2 Likes

Just wanted to update this. The pull request was merged in, so this should be available in the master branch. With luck it could be included in maya 2018, honestly unsure of when they cut that release.

1 Like

Nice! For now i used the workaround, thanks.