Skip to content

Commit c91a33b

Browse files
committed
add try/finally around import
to be sure we go back to the previous workspace, and that the callbacks are removed
1 parent e8d22b2 commit c91a33b

File tree

1 file changed

+17
-12
lines changed
  • Assets/Integrations/Autodesk/maya/scripts/unityOneClick

1 file changed

+17
-12
lines changed

Assets/Integrations/Autodesk/maya/scripts/unityOneClick/commands.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,23 @@ def doIt(self, args):
198198
self._tempName = None
199199
self._origItemsInScene = []
200200

201-
callbackId = OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeImportCheck, self.beforeImport)
202-
callbackId2 = OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterImport, self.afterImport)
203-
204-
strCmd = 'Import'
205-
self.displayDebug('doIt {0}'.format(strCmd))
206-
maya.cmds.Import()
207-
208-
OpenMaya.MMessage.removeCallback(callbackId)
209-
OpenMaya.MMessage.removeCallback(callbackId2)
210-
211-
if currWorkspace:
212-
maya.cmds.workspace(currWorkspace, o=True)
201+
callbackId = None
202+
callbackId2 = None
203+
try:
204+
callbackId = OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeImportCheck, self.beforeImport)
205+
callbackId2 = OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterImport, self.afterImport)
206+
207+
strCmd = 'Import'
208+
self.displayDebug('doIt {0}'.format(strCmd))
209+
maya.cmds.Import()
210+
finally:
211+
if currWorkspace:
212+
maya.cmds.workspace(currWorkspace, o=True)
213+
214+
if callbackId:
215+
OpenMaya.MMessage.removeCallback(callbackId)
216+
if callbackId2:
217+
OpenMaya.MMessage.removeCallback(callbackId2)
213218

214219
@classmethod
215220
def invoke(cls):

0 commit comments

Comments
 (0)