What scene was imported?

What scene was imported?

Anonymous
Not applicable
651 Views
2 Replies
Message 1 of 3

What scene was imported?

Anonymous
Not applicable

Hey guys,

 
I'm trying to catch some data about scenes that are imported.
 
Something like:
 
def import_callback():
    print "SOMETHING WAS IMPORTED. I WISH I KNEW WHAT IT WAS"
    
cmds.scriptJob( event=("SceneImported", import_callback) )
 
 It feels like a scriptJob callback is the way to go but I don't think it can capture the name/path of the file being imported.  Anyone have any insight or an alternate approach to calling some python on every import (and getting the name/path of the file imported)?
 
Thanks in advance. 
0 Likes
Accepted solutions (1)
652 Views
2 Replies
Replies (2)
Message 2 of 3

RFlannery1
Collaborator
Collaborator
Accepted solution

You can get the name using MSceneMessage.addCheckFileCallback.  Note that the below example is using the Maya Python API 2.0.  If you want to use the original Maya Python API, the callback parameters are a bit different.

import maya.api.OpenMaya as om

def importFileCallback(fileObj, _):
# fileObj is of type MFileObject
print fileObj.rawFullName()
print fileObj.expandedFullName()
# Returning False will cancel the import process
return True

cbId = om.MSceneMessage.addCheckFileCallback(om.MSceneMessage.kBeforeImportCheck, importFileCallback)

# If you want to stop running your callback function, use "removeCallback".
om.MMessage.removeCallback(cbId)

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Yep.  This works great.  Thanks.

0 Likes