maya kBeforeSave callback
<p>I need to register to some maya's MSceneMessage callback, and query the scene paths. I need to get both before and after's maya path. (open , save file)</p>

<p>Here's what I have so far.</p>

<pre><code>def before(*args, **kwargs):
    print 'BEFORE: ' + cmds.file(query = True)

def after(*args, **kwargs):
    print 'AFTER: ' + cmds.file(query = True)

om.MSceneMessage.addCallback(om.MSceneMessage.kBeforeOpen, before)
om.MSceneMessage.addCallback(om.MSceneMessage.kAfterOpen, after)

om.MSceneMessage.addCallback(om.MSceneMessage.kBeforeSave, before)
om.MSceneMessage.addCallback(om.MSceneMessage.kAfterSave, after)
</code></pre>

<p>Case scenario1; In scene test_01.ma, OPEN scene test_02.ma</p>

<p>Works as expected.</p>

<p>BEFORE: ../../test_01.ma</p>

<p>AFTER: ../../test_02.ma</p>

<p>Case scenario2; In scene test_01.ma, SAVE scene test_02.ma</p>

<p><strong>DOESN'T work as expected.</strong></p>

<p><strong>BEFORE: ../../test_02.ma</strong></p>

<p>AFTER: ../../test_02.ma</p>

<p>I also tried 'kBeforeSaveCheck' callback, with same result.</p>

<h1>get the <a href="http://download.autodesk.com/us/maya/2011help/CommandsPython/file.html" rel="nofollow">scenename</a></h1>

<pre><code>def scene_id(*args):
    return cmds.file(query=True, scenename=True)

def before(*args, **kwargs):
    print 'BEFORE: {0}'.format(scene_id())

def after(*args, **kwargs):
    print 'After: {0}'.format(scene_id())
</code></pre>

python api maya