Skip to content

Commit 6e45a5e

Browse files
committed
store model name and path after import
use path to export if we have it
1 parent 3065e50 commit 6e45a5e

File tree

1 file changed

+32
-1
lines changed
  • Assets/Integrations/Autodesk/maya2017/scripts/unityOneClick

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
3333
ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
3434

35+
UNITY_FBX_FILE_PATH = None
36+
UNITY_FBX_FILE_NAME = None
37+
3538
class BaseCommand(OpenMayaMPx.MPxCommand, LoggerMixin):
3639
"""
3740
Base class for UnityOneClick Plugin Commands.
@@ -69,6 +72,10 @@ class importCmd(BaseCommand):
6972

7073
def __init__(self):
7174
super(self.__class__, self).__init__()
75+
76+
# temporarily store the path and name of the imported FBX
77+
self._tempPath = None
78+
self._tempName = None
7279

7380
@classmethod
7481
def creator(cls):
@@ -83,11 +90,31 @@ def syntaxCreator(cls):
8390
def scriptCmd(cls):
8491
return
8592

93+
def beforeImport(self, retCode, file, clientData):
94+
# store path and filename
95+
self._tempPath = file.resolvedFullName()
96+
self._tempName = file.resolvedName()
97+
98+
def afterImport(self, *args, **kwargs):
99+
global UNITY_FBX_FILE_PATH
100+
global UNITY_FBX_FILE_NAME
101+
UNITY_FBX_FILE_PATH = self._tempPath
102+
UNITY_FBX_FILE_NAME = self._tempName
103+
86104
def doIt(self, args):
105+
self._tempPath = None
106+
self._tempName = None
107+
108+
callbackId = OpenMaya.MSceneMessage.addCheckFileCallback(OpenMaya.MSceneMessage.kBeforeImportCheck, self.beforeImport)
109+
callbackId2 = OpenMaya.MSceneMessage.addCallback(OpenMaya.MSceneMessage.kAfterImport, self.afterImport)
110+
87111
strCmd = 'Import'
88112
self.displayDebug('doIt {0}'.format(strCmd))
89113
maya.mel.eval(strCmd)
90114

115+
OpenMaya.MMessage.removeCallback(callbackId)
116+
OpenMaya.MMessage.removeCallback(callbackId2)
117+
91118
@classmethod
92119
def invoke(cls):
93120
"""
@@ -204,7 +231,11 @@ def doIt(self, args):
204231
if not self.loadDependencies():
205232
return
206233

207-
strCmd = 'SendToUnitySelection'
234+
global UNITY_FBX_FILE_PATH
235+
if UNITY_FBX_FILE_PATH:
236+
strCmd = r'file -force -options "" -typ "FBX export" -pr -es "{0}"'.format(UNITY_FBX_FILE_PATH);
237+
else:
238+
strCmd = 'SendToUnitySelection'
208239
self.displayDebug('doIt {0}'.format(strCmd))
209240
maya.mel.eval(strCmd)
210241

0 commit comments

Comments
 (0)