32
32
ctypes .pythonapi .PyCObject_AsVoidPtr .restype = ctypes .c_void_p
33
33
ctypes .pythonapi .PyCObject_AsVoidPtr .argtypes = [ctypes .py_object ]
34
34
35
+ UNITY_FBX_FILE_PATH = None
36
+ UNITY_FBX_FILE_NAME = None
37
+
35
38
class BaseCommand (OpenMayaMPx .MPxCommand , LoggerMixin ):
36
39
"""
37
40
Base class for UnityOneClick Plugin Commands.
@@ -69,6 +72,10 @@ class importCmd(BaseCommand):
69
72
70
73
def __init__ (self ):
71
74
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
72
79
73
80
@classmethod
74
81
def creator (cls ):
@@ -83,11 +90,31 @@ def syntaxCreator(cls):
83
90
def scriptCmd (cls ):
84
91
return
85
92
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
+
86
104
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
+
87
111
strCmd = 'Import'
88
112
self .displayDebug ('doIt {0}' .format (strCmd ))
89
113
maya .mel .eval (strCmd )
90
114
115
+ OpenMaya .MMessage .removeCallback (callbackId )
116
+ OpenMaya .MMessage .removeCallback (callbackId2 )
117
+
91
118
@classmethod
92
119
def invoke (cls ):
93
120
"""
@@ -204,7 +231,11 @@ def doIt(self, args):
204
231
if not self .loadDependencies ():
205
232
return
206
233
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'
208
239
self .displayDebug ('doIt {0}' .format (strCmd ))
209
240
maya .mel .eval (strCmd )
210
241
0 commit comments