Skip to content

Commit 4bc4b01

Browse files
committed
add ability to export multiple sets by selection
1 parent d42cd4c commit 4bc4b01

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

Assets/Integrations/Autodesk/max/scripts/UnityFbxForMaxPlugin.ms

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macroScript UnityImport category:"Unity" tooltip:"Import an FBX file from a Unit
6767
fn getOrCreateSettingsDummy name = (
6868
unityDummy = getOrCreateDummy name
6969

70-
if not (isProperty unityDummy "filePath") do (
70+
if not (isProperty unityDummy "modelFilePath") do (
7171
unitySetData = attributes unityData
7272
(
7373
parameters main rollout:params
@@ -204,31 +204,74 @@ macroScript UnityExport category:"Unity" tooltip:"Export a model to Unity"
204204
FbxExporterSetParam "ScaleFactor" (unitToScaleFactor units.SystemType)
205205
);
206206

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+
207239
-- Make sure the FbxExporter plugin is loaded
208240
pluginManager.loadClass FbxExporter
209241

210242
loadUnityFbxExportSettings()
211243

212244
origSelection = getCurrentSelection()
213-
exportSet = selectionSets["UnityFbxExportSet"]
214-
if not isdeleted exportSet and exportSet != undefined then(
215-
select exportSet
216-
)
217245

218246
local origUnits = units.SystemType
219247
units.SystemType = #Centimeters
220248

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+
)
228261
)
229262

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+
)
232275
)
233276

234277
units.SystemType = origUnits

0 commit comments

Comments
 (0)