@@ -64,7 +64,8 @@ def loadUnityFbxExportSettings(self):
64
64
"""
65
65
Load the Export Settings from file
66
66
"""
67
- fileName = maya .cmds .optionVar (q = "UnityFbxExportSettings" )
67
+ projectPath = maya .cmds .optionVar (q = "UnityProject" )
68
+ fileName = os .path .join (projectPath ,"Assets" , maya .cmds .optionVar (q = "UnityFbxExportSettings" ))
68
69
if not os .path .isfile (fileName ):
69
70
maya .cmds .error ("Failed to find Unity Fbx Export Settings at: {0}" .format (fileName ))
70
71
return False
@@ -146,6 +147,20 @@ def beforeImport(self, retCode, file, clientData):
146
147
def afterImport (self , * args , ** kwargs ):
147
148
if self ._tempPath :
148
149
self .storeAttribute (self ._exportSet , self ._unityFbxFilePathAttr , self ._tempPath )
150
+
151
+ # Change Unity project if fbx is from a different Unity project.
152
+ # Get the project based on the folder structure (i.e. folder above Assets)
153
+ head ,tail = os .path .split (self ._tempPath )
154
+ # Check that we are not at the root directory.
155
+ # os.path.dirname(head) returns the last directory name in the path,
156
+ # or head if head is the root directory.
157
+ while head and os .path .dirname (head ) != head :
158
+ if tail == "Assets" :
159
+ # this is a valid Unity project, so set it
160
+ maya .cmds .optionVar (sv = ('UnityProject' , head ))
161
+ break
162
+ head ,tail = os .path .split (head )
163
+
149
164
if self ._tempName :
150
165
self .storeAttribute (self ._exportSet , self ._unityFbxFileNameAttr , self ._tempName )
151
166
@@ -161,6 +176,12 @@ def afterImport(self, *args, **kwargs):
161
176
162
177
def doIt (self , args ):
163
178
self .loadDependencies ()
179
+
180
+ # set Unity project as the current workspace
181
+ currWorkspace = maya .cmds .workspace (o = True , q = True )
182
+ unityProject = maya .cmds .optionVar (q = 'UnityProject' )
183
+ if unityProject :
184
+ maya .cmds .workspace (unityProject , o = True )
164
185
165
186
self ._tempPath = None
166
187
self ._tempName = None
@@ -175,6 +196,9 @@ def doIt(self, args):
175
196
176
197
OpenMaya .MMessage .removeCallback (callbackId )
177
198
OpenMaya .MMessage .removeCallback (callbackId2 )
199
+
200
+ if currWorkspace :
201
+ maya .cmds .workspace (currWorkspace , o = True )
178
202
179
203
@classmethod
180
204
def invoke (cls ):
@@ -217,7 +241,7 @@ def doIt(self, args):
217
241
218
242
unityAppPath = maya .cmds .optionVar (q = 'UnityApp' )
219
243
unityProjectPath = maya .cmds .optionVar (q = 'UnityProject' )
220
- unityTempSavePath = maya .cmds .optionVar (q = 'UnityTempSavePath' )
244
+ unityTempSavePath = os . path . join ( unityProjectPath , "Assets" , maya .cmds .optionVar (q = 'UnityTempSavePath' ) )
221
245
unityCommand = "FbxExporters.Review.TurnTable.LastSavedModel"
222
246
223
247
if not self .loadUnityFbxExportSettings ():
@@ -235,8 +259,10 @@ def doIt(self, args):
235
259
# save fbx to Assets/_safe_to_delete/
236
260
savePath = unityTempSavePath
237
261
maya .cmds .sysFile (savePath , makeDir = True )
238
- savePath = savePath + "/TurnTableModel.fbx"
239
- maya .mel .eval (r'file -force -options "" -typ "FBX export" -pr -es "{0}"' .format (savePath ));
262
+ savePath = os .path .join (savePath , "TurnTableModel.fbx" )
263
+ savePath = os .path .abspath (savePath )
264
+
265
+ maya .cmds .file (savePath , force = True , options = "" , typ = "FBX export" , pr = True , es = True )
240
266
241
267
if maya .cmds .about (macOS = True ):
242
268
# Use 'open -a' to bring app to front if it has already been started.
0 commit comments