-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmayaDependencies.py
85 lines (62 loc) · 3.02 KB
/
mayaDependencies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from filesystem import Path
import os
import sys
import dependencies
import api
import maya
import baseMelUI
import maya.cmds as cmd
def flush():
pluginPaths = map( Path, api.mel.eval( 'getenv MAYA_PLUG_IN_PATH' ).split( ';' ) ) #NOTE: os.environ is different from the getenv call, and getenv isn't available via python... yay!
#before we do anything we need to see if there are any plugins in use that are python scripts - if there are, we need to ask the user to close the scene
#now as you might expect maya is a bit broken here - querying the plugins in use doesn't return reliable information - instead we ask for all loaded
#plugins, to which maya returns a list of extension-less plugin names. We then have to map those names back to disk by searching the plugin path and
#determining whether the plugins are binary or scripted plugins, THEN we need to see which the scripted ones are unloadable.
loadedPluginNames = cmd.pluginInfo( q=True, ls=True ) or []
loadedScriptedPlugins = []
for pluginName in loadedPluginNames:
for p in pluginPaths:
possiblePluginPath = (p / pluginName).setExtension( 'py' )
if possiblePluginPath.exists():
loadedScriptedPlugins.append( possiblePluginPath[-1] )
initialScene = None
for plugin in loadedScriptedPlugins:
if not cmd.pluginInfo( plugin, q=True, uo=True ):
BUTTONS = YES, NO = 'Yes', 'NO'
ret = cmd.confirmDialog( t='Plugins in Use!', m="Your scene has python plugins in use - these need to be unloaded to properly flush.\n\nIs it cool if I close the current scene? I'll prompt to save your scene...\n\nNOTE: No flushing has happened yet!", b=BUTTONS, db=NO )
if ret == NO:
print "!! FLUSH ABORTED !!"
return
initialScene = cmd.file( q=True, sn=True )
#prompt to make new scene if there are unsaved changes...
api.mel.saveChanges( 'file -f -new' )
break
#now unload all scripted plugins
for plugin in loadedScriptedPlugins:
cmd.unloadPlugin( plugin ) #we need to unload the plugin so that it gets reloaded (it was flushed) - it *may* be nessecary to handle the plugin reload here, but we'll see how things go for now
#lastly, close all windows managed by baseMelUI - otherwise callbacks may fail...
for melUI in baseMelUI.BaseMelWindow.IterInstances():
melUI.delete()
#determine the location of maya lib files - we don't want to flush them either
mayaLibPath = Path( maya.__file__ ).up( 2 )
#flush all modules
dependencies.flush( [ mayaLibPath ] )
if initialScene and not cmd.file( q=True, sn=True ):
if Path( initialScene ).exists():
cmd.file( initialScene, o=True )
print "WARNING: You'll need to close and re-open any python based tools that are currently open..."
def reconnect():
#try to import wing
import wingdbstub
wingdbstub.Ensure()
import time
try:
debugger = wingdbstub.debugger
except AttributeError:
print "No debugger found!"
else:
if debugger is not None:
debugger.StopDebug()
time.sleep( 1 )
debugger.StartDebug()
#end