@@ -67,7 +67,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
67
67
fn getOrCreateSettingsDummy name = (
68
68
unityDummy = getOrCreateDummy name
69
69
70
- if not (isProperty unityDummy " filePath " ) do (
70
+ if not (isProperty unityDummy " modelFilePath " ) do (
71
71
unitySetData = attributes unityData
72
72
(
73
73
parameters main rollout: params
@@ -204,31 +204,74 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
204
204
FbxExporterSetParam " ScaleFactor" (unitToScaleFactor units.SystemType)
205
205
);
206
206
207
+ fn getUnityExportSets = (
208
+ local unityExportSets = #()
209
+ for expSet in selectionSets do (
210
+ if (matchPattern expSet.name pattern: " *_UnityExportSet" and (not isdeleted expSet) and (expSet != undefined )) do (
211
+ append unityExportSets expSet
212
+ )
213
+ )
214
+ unityExportSets
215
+ )
216
+
217
+ fn exportUnitySet expSet = (
218
+ select expSet
219
+
220
+ -- get export set's dummy
221
+ local expSetDummy = getNodeByName (expSet.name)
222
+
223
+ exportFileName = undefined
224
+ if expSetDummy != undefined and (isProperty expSetDummy " modelFilePath" ) and (isProperty expSetDummy " modelFileName" ) and
225
+ expSetDummy.unityData.modelFilePath != " " and expSetDummy.unityData.modelFileName != " " then
226
+ (
227
+ exportFileName = expSetDummy.unityData.modelFilePath + " /" + expSetDummy.unityData.modelFileName
228
+ )
229
+ else (
230
+ unityProjectPath = getINISetting (GetMAXIniFile()) " Unity" " UnityProject"
231
+ exportFileName = getSaveFileName caption: " Export FBX to Unity" filename: (unityProjectPath + " /Assets/" ) types: " FBX (*.fbx)|*.fbx|"
232
+ )
233
+
234
+ if exportFileName != undefined then (
235
+ exportFile exportFileName #noPrompt selectedOnly: true using: FBXEXP
236
+ )
237
+ )
238
+
207
239
-- Make sure the FbxExporter plugin is loaded
208
240
pluginManager.loadClass FbxExporter
209
241
210
242
loadUnityFbxExportSettings()
211
243
212
244
origSelection = getCurrentSelection()
213
- exportSet = selectionSets[" UnityFbxExportSet" ]
214
- if not isdeleted exportSet and exportSet != undefined then (
215
- select exportSet
216
- )
217
245
218
246
local origUnits = units.SystemType
219
247
units.SystemType = #Centimeters
220
248
221
- exportFileName = undefined
222
- if unityFbxFilePathAttr != undefined and unityFbxFileNameAttr != undefined then (
223
- exportFileName = unityFbxFilePathAttr + unityFbxFileNameAttr
224
- )
225
- else (
226
- unityProjectPath = getINISetting (GetMAXIniFile()) " Unity" " UnityProject"
227
- exportFileName = getSaveFileName caption: " Export FBX to Unity" filename: (unityProjectPath + " /Assets/" ) types: " FBX (*.fbx)|*.fbx|"
249
+ -- get all the unity export sets
250
+ local unityExportSets = getUnityExportSets()
251
+
252
+ -- find all sets that contain at least one object from the current selection
253
+ local setsToExport = #()
254
+ for expSet in unityExportSets do (
255
+ for obj in origSelection do (
256
+ if (findItem expSet obj > 0 ) do (
257
+ appendIfUnique setsToExport expSet
258
+ break
259
+ )
260
+ )
228
261
)
229
262
230
- if exportFileName != undefined then (
231
- exportFile exportFileName #noPrompt selectedOnly: true using: FBXEXP
263
+ -- if no sets are selected, then export selection, otherwise export each set to its corresponding file
264
+ if (setsToExport.count <= 0 ) then (
265
+ local unityProjectPath = getINISetting (GetMAXIniFile()) " Unity" " UnityProject"
266
+ local exportFileName = getSaveFileName caption: " Export FBX to Unity" filename: (unityProjectPath + " /Assets/" ) types: " FBX (*.fbx)|*.fbx|"
267
+ if exportFileName != undefined do (
268
+ exportFile exportFileName #noPrompt selectedOnly: true using: FBXEXP
269
+ )
270
+ )
271
+ else (
272
+ for expSet in setsToExport do (
273
+ exportUnitySet expSet
274
+ )
232
275
)
233
276
234
277
units.SystemType = origUnits
0 commit comments