34
34
35
35
import os
36
36
37
- # Global variables set on import, to be used for publishing.
38
- # The variables are set in the afterImport function (a callback for OpenMaya.MSceneMessage.kAfterImport)
39
- # in the importCmd class, and used by the publishCmd.doIt() function.
40
- unity_fbx_file_path = None
41
- unity_fbx_file_name = None
42
-
43
37
class BaseCommand (OpenMayaMPx .MPxCommand , LoggerMixin ):
44
38
"""
45
39
Base class for UnityOneClick Plugin Commands.
@@ -48,6 +42,8 @@ def __init__(self):
48
42
OpenMayaMPx .MPxCommand .__init__ (self )
49
43
LoggerMixin .__init__ (self )
50
44
self ._exportSet = "UnityFbxExportSet"
45
+ self ._unityFbxFilePathAttr = "unityFbxFilePath"
46
+ self ._unityFbxFileNameAttr = "unityFbxFileName"
51
47
52
48
def __del__ (self ):
53
49
LoggerMixin .__del__ (self )
@@ -118,17 +114,27 @@ def beforeImport(self, retCode, file, clientData):
118
114
self ._tempName = file .resolvedName ()
119
115
120
116
def afterImport (self , * args , ** kwargs ):
121
- global unity_fbx_file_path
122
- global unity_fbx_file_name
123
- unity_fbx_file_path = self ._tempPath
124
- unity_fbx_file_name = self ._tempName
117
+ if self ._tempPath :
118
+ if not maya .mel .eval ('attributeExists "{0}" "{1}"' .format (self ._unityFbxFilePathAttr , self ._exportSet )):
119
+ maya .cmds .addAttr (self ._exportSet , shortName = self ._unityFbxFilePathAttr , storable = True , dataType = "string" )
120
+ maya .cmds .setAttr ("{0}.{1}" .format (self ._exportSet , self ._unityFbxFilePathAttr ), self ._tempPath , type = "string" )
121
+ if self ._tempName :
122
+ if not maya .mel .eval ('attributeExists "{0}" "{1}"' .format (self ._unityFbxFileNameAttr , self ._exportSet )):
123
+ maya .cmds .addAttr (self ._exportSet , shortName = self ._unityFbxFileNameAttr , storable = True , dataType = "string" )
124
+ maya .cmds .setAttr ("{0}.{1}" .format (self ._exportSet , self ._unityFbxFileNameAttr ), self ._tempName , type = "string" )
125
125
126
126
def doIt (self , args ):
127
127
self .loadDependencies ()
128
128
129
129
self ._tempPath = None
130
130
self ._tempName = None
131
131
132
+ # Get or create the Unity Fbx Export Set
133
+ allSets = maya .cmds .listSets (allSets = True )
134
+ if not self ._exportSet in allSets :
135
+ # couldn't find export set so create it
136
+ maya .cmds .sets (name = self ._exportSet )
137
+
132
138
callbackId = OpenMaya .MSceneMessage .addCheckFileCallback (OpenMaya .MSceneMessage .kBeforeImportCheck , self .beforeImport )
133
139
callbackId2 = OpenMaya .MSceneMessage .addCallback (OpenMaya .MSceneMessage .kAfterImport , self .afterImport )
134
140
@@ -142,14 +148,8 @@ def doIt(self, args):
142
148
# figure out what has been added after import
143
149
itemsInScene = maya .cmds .ls (tr = True , o = True , r = True )
144
150
newItems = list (set (itemsInScene ) - set (origItemsInScene ))
145
-
146
- # Get or create the Unity Fbx Export Set
147
- allSets = maya .cmds .listSets (allSets = True )
148
- if not self ._exportSet in allSets :
149
- # couldn't find export set so create it
150
- maya .cmds .sets (name = self ._exportSet )
151
151
152
- maya .cmds .sets (newItems , add = self ._exportSet )
152
+ maya .cmds .sets (newItems , add = self ._exportSet )
153
153
154
154
OpenMaya .MMessage .removeCallback (callbackId )
155
155
OpenMaya .MMessage .removeCallback (callbackId2 )
@@ -276,8 +276,11 @@ def doIt(self, args):
276
276
if not self .loadUnityFbxExportSettings ():
277
277
return
278
278
279
- global unity_fbx_file_path
280
- global unity_fbx_file_name
279
+ if maya .mel .eval ('attributeExists "{0}" "{1}"' .format (self ._unityFbxFilePathAttr , self ._exportSet )) and \
280
+ maya .mel .eval ('attributeExists "{0}" "{1}"' .format (self ._unityFbxFileNameAttr , self ._exportSet )):
281
+ unity_fbx_file_path = maya .cmds .getAttr ("{0}.{1}" .format (self ._exportSet , self ._unityFbxFilePathAttr ))
282
+ unity_fbx_file_name = maya .cmds .getAttr ("{0}.{1}" .format (self ._exportSet , self ._unityFbxFileNameAttr ))
283
+
281
284
if unity_fbx_file_path and unity_fbx_file_name :
282
285
strCmd = r'file -force -options "" -typ "FBX export" -pr -es "{0}{1}"' .format (unity_fbx_file_path , unity_fbx_file_name );
283
286
else :
0 commit comments