Skip to content

Commit 610e538

Browse files
committed
store the fbx file path and name as attributes
so that they will persist in the saved project
1 parent 056a6e3 commit 610e538

File tree

1 file changed

+22
-19
lines changed
  • Assets/Integrations/Autodesk/maya2017/scripts/unityOneClick

1 file changed

+22
-19
lines changed

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434

3535
import os
3636

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-
4337
class BaseCommand(OpenMayaMPx.MPxCommand, LoggerMixin):
4438
"""
4539
Base class for UnityOneClick Plugin Commands.
@@ -48,6 +42,8 @@ def __init__(self):
4842
OpenMayaMPx.MPxCommand.__init__(self)
4943
LoggerMixin.__init__(self)
5044
self._exportSet = "UnityFbxExportSet"
45+
self._unityFbxFilePathAttr = "unityFbxFilePath"
46+
self._unityFbxFileNameAttr = "unityFbxFileName"
5147

5248
def __del__(self):
5349
LoggerMixin.__del__(self)
@@ -118,17 +114,27 @@ def beforeImport(self, retCode, file, clientData):
118114
self._tempName = file.resolvedName()
119115

120116
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")
125125

126126
def doIt(self, args):
127127
self.loadDependencies()
128128

129129
self._tempPath = None
130130
self._tempName = None
131131

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+
132138
callbackId = OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeImportCheck, self.beforeImport)
133139
callbackId2 = OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterImport, self.afterImport)
134140

@@ -142,14 +148,8 @@ def doIt(self, args):
142148
# figure out what has been added after import
143149
itemsInScene = maya.cmds.ls(tr=True, o=True, r=True)
144150
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)
151151

152-
maya.cmds.sets(newItems, add=self._exportSet)
152+
maya.cmds.sets(newItems, add=self._exportSet)
153153

154154
OpenMaya.MMessage.removeCallback(callbackId)
155155
OpenMaya.MMessage.removeCallback(callbackId2)
@@ -276,8 +276,11 @@ def doIt(self, args):
276276
if not self.loadUnityFbxExportSettings():
277277
return
278278

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+
281284
if unity_fbx_file_path and unity_fbx_file_name:
282285
strCmd = r'file -force -options "" -typ "FBX export" -pr -es "{0}{1}"'.format(unity_fbx_file_path, unity_fbx_file_name);
283286
else:

0 commit comments

Comments
 (0)