it can actually be done pretty simply, but here is a couple functions that you can use with a few more options.
--wanky recursive function to parse hierarchy into an array
fn addChildrenToArray theChildren currentObjsToExport =
(
for c in theChildren do
(
append currentObjsToExport c
addChildrenToArray c.children currentObjsToExport
)
)
-- Export the selection.. with the option to export each selected object seperately (hier:false) or to export each hierarchy to seperate objects (hier:true)
-- exported filenames will be the same as the
fn massExportfn hier path filetype =
(
exportSelection = selection as array
--if we're doing seperate hierarchys, then only keep the objects that have no parent in the selection
if hier == true then
(
baseNodesToExport = for o in exportSelection where o.parent == undefined collect o
)
else baseNodesToExport = exportSelection
--parse through said root nodes
for o in baseNodesToExport do
(
--save old position, export at 0,0,0, restore to old position
oldPos = o.position
o.position =
--children returns a 'NodeChildrenArray, so convert that to an array manually.
--include the current node in the array no matter what.
currentObjsToExport = #(o)
-- if we're packaging hierarchys then collect childrem
if hier == true do
(
addChildrenToArray o.children currentObjsToExport
)
select currentObjsToExport
--random info for use to ogle at the export.. yea yea
format "\tExport:\t%\tas\t%\n" o.name filetype
format "\tTo:\t%\n" (path + "/" + o.name + filetype)
format "\n-----------------------------\n\n"
-- if we need to save selected use this export type to blow the objects out to maxfiles
if filetype == ".MAX" then ( savenodes currentObjsToExport (path + "/" + o.name + filetype) quiet:true )
else
(
--export using the name of the root node as the filename
exportfile (path + "/" + o.name + filetype) #noPrompt selectedOnly:true
)
o.position = oldPos
)
select exportSelection
)
massExportfn true "C:\Temp" ".X"