--this script is made by Anton Berg at www.os3d.se --anton[at]os3d.se escapeenable = true rollout ExportObj "OS3D.se Mass export Selected objects v1.6" width:341 height:262 ( global theClasses global outPath local debug = false edittext edtPrefixText "Prefix" pos:[25,79] width:226 height:16 readOnly:false button btnStartExport "Start Export" pos:[248,172] width:90 height:86 checkbox chkAddPrefix "" pos:[7,78] width:15 height:16 checked:true toolTip:"if checked the Prefix is added to the filename" dropdownList ddl2 "FileType" pos:[7,6] width:244 height:40 checkbox chkDebug "Debug" pos:[264,105] width:56 height:16 checked:false toolTip:"This will show error messages" spinner spnNrOfDigits "Digits" pos:[110,104] width:57 height:16 range:[0,100,7] type:#integer checkbox chkAddZeros "Add Zeros" pos:[7,104] width:80 height:16 checked:true edittext edtFrameRange "Frame Range" pos:[8,55] width:243 height:16 readOnly:false spinner spnFrameByStep "By Step" pos:[285,55] width:49 height:16 range:[0,1000,1] label lblStatus "Info window" pos:[9,179] width:231 height:70 GroupBox grp1 "Info" pos:[2,165] width:244 height:93 spinner spnOffset "Offset" pos:[192,104] width:59 height:16 range:[-10000,10000,0] type:#integer button btn2 "Browse output" pos:[134,136] width:204 height:24 toolTip:"Output folder" checkbox chkSingleMesh "SingleMesh" pos:[264,80] width:72 height:16 checked:false toolTip:"This combines all objects in a group into one single mesh... can be useful in some cases" button btnResetIniFile "R" pos:[312,1] width:26 height:21 toolTip:"This resets the parameters to the default values, there is no undo for this..." button btnSelectVisibleObjects "Select Visible geometry" pos:[7,136] width:120 height:24 toolTip:"This just helps you select all geometry that are currently visible in the viewport.." checkbox chkAddFrame "add Frame" pos:[264,28] width:72 height:16 checked:true toolTip:"if this is checked the scripts appends the frame to the object name, useful when exporting ranges" -------Start function definitioin fn CheckIfFloatIsInt invalue = ( inval = invalue as float tempval = filterstring (inval as string) "." if tempval[2] == "0" then return true else return false ) fn OS3DGetRanges OS3DRange OS3DByStep = ( --usage: FrameRange = OS3DGetRanges "10-20,31,35,36" 1.0 --OS3DByStep = 1.1 byStep = (if CheckIfFloatIsInt (OS3DByStep as float) then (OS3DByStep as integer) else (OS3DByStep as float)) FrameArray = #() print "---start range processing---" inputString = filterString OS3DRange "," splitEmptytokens:false for str in inputstring do ( if (matchpattern str pattern:"*-*") then ( print "Found a range" tmpString = filterString str "-" splitEmptytokens:false OS3DStartFrame = tmpString[1] as float OS3DEndFrame = tmpString[2] as float for i = OS3DStartFrame to OS3DEndFrame by ByStep do --collect (i) ( if CheckIfFloatIsInt (OS3DByStep as float) then ( appendIfUnique FrameArray (i as integer) ) else ( appendIfUnique FrameArray (i as float) ) ) ) --end then else ( print "Found single frame" if CheckIfFloatIsInt (OS3DByStep as float) then ( appendIfUnique FrameArray (str as integer) ) else ( appendIfUnique FrameArray (str as float) ) ) -- end else ) --sort FrameArray return FrameArray ) fn OS3DFileName inputPath objName UsePrefix Prefix UseZeroPadding NrDigits FrmNr FrmOffset AddFrameNumber = ( --usage: OS3DFileName $.name true "myPrefix" true 5 17.4 NewName = inputPath + "\\" FrameNr = (FrmOffset + FrmNr) as string FrameNameArray = FilterString FrameNr "." --replace the "." in a float value if FrameNameArray.count == 2 then ( FrameNr = FrameNameArray[1] + "_" + FrameNameArray[2] ) if UsePrefix then ( NewName += (Prefix + "-") ) NewName += objName if AddFrameNumber then ( NewName += "-" ) if AddFrameNumber then ( if UseZeroPadding then ( ZeroNumber = "" fr = FrameNr as string AddNrZeros = NrDigits - fr.count for i = 1 to AddNrZeros do ( ZeroNumber += "0" ) ZeroNumber += fr NewName += ("Frame_" + ZeroNumber as string) ) else ( NewName += ("Frame_" + FrameNr as string) ) ) --end use frame number NewName ) fn OS3D_isGroupMasterHead item = ( objArray = #() ab_gh = isGroupHead item ab_gp = item.parent == undefined if ab_gh and ab_gp do ( print ("the master is:" + item.name) join objArray item.children append objArray item ) return objArray ) fn OS3D_item_name itemArray = ( for item in itemArray do ( belongToGroup = false ab_gh = isGroupHead item ab_gp = item.parent == undefined if ab_gh and ab_gp do ( belongToGroup = true return item.name ) ) return "" ) fn NewfileName inputPath objName ischecked nr= ( if ischecked == true then ( --set the filename to this prefix np = inputPath + "\\" + objName + "_"+ nr as string --+".obj" if debug then print np ) else ( --set the filename to the object filename np = inputPath + "\\" + objName --e+ ".obj" if debug then print np ) return np ) fn SnapshotSelectionIntoMesh selObjs theTime = ( snaphostArray = for o in selObjs where (superclassof o == GeometryClass) collect ( with animate on ( --slidertime = theTime oldparent = o.parent o.parent = undefined MeshObj = at time slidertime snapshot o o.parent = oldparent ) MeshObj ) if snaphostArray.count > 1 then ( for m = 2 to snaphostArray.count do (attach snaphostArray[1] snaphostArray[m]) ) return snaphostArray[1] ) fn OS3DDoExport SelOnly ShowPrompt fname asSingleMesh theTime= ( --usage OS3DDoExport true true result = false if ShowPrompt then ( print fname if asSingleMesh then ( selObjs = (selection as array) --thetime = slidertime SingleObj = SnapshotSelectionIntoMesh selObjs theTime select SingleObj result = (exportFile fname using:(theClasses[ddl2.selection]) selectedOnly: SelOnly) delete SingleObj ) else ( result = (exportFile fname using:(theClasses[ddl2.selection]) selectedOnly: SelOnly) ) ) --end showprompt = yes else --if promt = no ( print fname if asSingleMesh then ( selObjs = (selection as array) --thetime = slidertime SingleObj = SnapshotSelectionIntoMesh selObjs theTime print selObjs select SingleObj result = (exportFile fname #noPrompt using:(theClasses[ddl2.selection]) selectedOnly: SelOnly) delete SingleObj ) else ( result = (exportFile fname #noPrompt using:(theClasses[ddl2.selection]) selectedOnly: SelOnly) ) )--- end prompt = no if result != true then ( if chkDebug.state == true then (messageBox "OS3D debug INFO:\nYou have a selected a filformat that doesn´t except the selected only state..") result = (exportFile fname using:(theClasses[ddl2.selection]) selectedOnly: false) ) ) fn StatusText = ( try ( TimeRange = OS3DGetRanges edtFrameRange.text spnFrameByStep.value lblStatus.caption = ("Number of frames that will be exported: " + TimeRange.count as string + "\n") objsArray = (selection as array) fname = OS3DFileName "" objsArray[1].name chkAddPrefix.state edtPrefixText.text chkAddZeros.state spnNrOfDigits.value TimeRange[TimeRange.count] spnOffset.value chkAddFrame.state --fname = OS3DFileName "" "ExampleName" true "prefix" true 7 42.0 lblStatus.caption += ("Example Filename for current selection:\n" + fname) ) catch(if chkDebug.state do (print "Status update did not work")) ) struct OS3D_iniFunctions ( fn iniFileName = ("os3d_massExportObj.ini" ), fn OS3D_SetIniSetting iniSection iniKey iniVal = ( --creates a new setting and stores it in the inifile under the users local setting iniFolder = getdir #plugcfg iniFilePath = ( inifolder + "\\"+OS3D_iniFunctions.iniFileName()) returnVal = setINISetting iniFilePath iniSection iniKey (iniVal as string) if debug then ( if returnVal then ( format "\n\n==OS3D ini store\nValue: \n %\nwas written to key: \n % \nand stored in ini file:\n %\n" iniVal iniKey iniFilePath ) else ( format "FAILED TO WRITE - Value: % was written to key: % and stored in ini file:\n%" iniVal iniKey iniFilePath ) ) ), fn OS3D_GetIniSetting iniSection iniKey = ( --gets a setting iniFolder = getdir #plugcfg iniFilePath = ( inifolder + "\\"+OS3D_iniFunctions.iniFileName()) if (OS3D_iniFunctions.OS3D_ExistIniFile()) then ( if (hasINISetting iniFilePath iniSection iniKey) then ( returnVal = getINISetting iniFilePath iniSection iniKey if debug then ( if returnVal != "" then ( format "\n\n==OS3D ini load\nValue: \n %\nwas loaded from key: \n % \n stored in ini file:\n %\n" returnVal iniKey iniFilePath ) else ( format "got empty value: % could be the correct key: % that is stored in ini file:\n%\ncould also mean that the inifile does not exist or this user has no access to it" returnVal iniKey iniFilePath ) ) returnVal ) else ( format "ini file does not have this key: % set.." iniKey returnVal = "" ) ) else ( print "no inifile exists.." ) ), fn OS3D_RemoveIniFile = ( iniFolder = getdir #plugcfg iniFilePath = ( inifolder + "\\"+OS3D_iniFunctions.iniFileName()) deletefile iniFilePath ), fn OS3D_ExistIniFile = ( iniFolder = getdir #plugcfg iniFilePath = ( inifolder + "\\"+OS3D_iniFunctions.iniFileName()) (getFiles iniFilePath).count > 0 ) ) --OS3D_iniFunctions.OS3D_RemoveIniFile() fn os3d_createDefaultSettings = ( OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "FrameRange" "1-10,13,16,30-35" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "PrefixText" "MyPrefixText" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "PrefixUse" "true" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "addZeros" "true" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "Digits" "7" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "Offset" "0" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "ByStep" "1" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "SingleMesh" "false" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "debug" "false" OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "selectedPlugin" "1" OS3D_iniFunctions.OS3D_SetIniSetting "FilePaths" "outputFolder" "c:\\temp\\" --"true" as booleanClass ) fn OS3D_LoadIniSettings DialogWindowInstance = ( if ( OS3D_iniFunctions.OS3D_ExistIniFile() ) then ( DialogWindowInstance.edtFrameRange.text = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "FrameRange") DialogWindowInstance.edtPrefixText.text = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "PrefixText") DialogWindowInstance.chkAddPrefix.state =(OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "PrefixUse") as booleanclass DialogWindowInstance.ddl2.selection = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "selectedPlugin") as integer DialogWindowInstance.chkDebug.state = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "debug") as booleanclass DialogWindowInstance.spnNrOfDigits.value = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "Digits") as integer DialogWindowInstance.chkAddZeros.state = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "addZeros") as booleanClass DialogWindowInstance.spnFrameByStep.value = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "ByStep") as float DialogWindowInstance.spnOffset.value = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "Offset") as integer DialogWindowInstance.chkSingleMesh.state = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "SingleMesh") as booleanClass DialogWindowInstance.chkAddFrame.state = (OS3D_iniFunctions.OS3D_GetIniSetting "Parameters" "AddFrameNumber") as booleanClass DialogWindowInstance.btn2.caption = outPath = OS3D_iniFunctions.OS3D_GetIniSetting "FilePaths" "outputFolder" ) ) fn OS3D_SaveIniSettings DialogWindowInstance = ( OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "FrameRange" DialogWindowInstance.edtFrameRange.text OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "PrefixText" DialogWindowInstance.edtPrefixText.text OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "PrefixUse" DialogWindowInstance.chkAddPrefix.state OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "selectedPlugin" DialogWindowInstance.ddl2.selection OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "debug" DialogWindowInstance.chkDebug.state OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "Digits" DialogWindowInstance.spnNrOfDigits.value OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "addZeros" DialogWindowInstance.chkAddZeros.state OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "ByStep" DialogWindowInstance.spnFrameByStep.value OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "Offset" DialogWindowInstance.spnOffset.value OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "SingleMesh" DialogWindowInstance.chkSingleMesh.state OS3D_iniFunctions.OS3D_SetIniSetting "Parameters" "AddFrameNumber" DialogWindowInstance.chkAddFrame.state OS3D_iniFunctions.OS3D_SetIniSetting "FilePaths" "outputFolder" outPath ) -- OS3D_iniFunctions.OS3D_SetIniSetting "Test section" "antonKey" "tempoLama" -- OS3D_iniFunctions.OS3D_GetIniSetting "Test section" "antonKey" --OS3D_iniFunctions.OS3D_RemoveIniFile() ------end function definition---- on ExportObj open do ( theClasses = exporterPlugin.classes theClassesNames = #() for exptyp in theClasses do ( append theClassesNames (exptyp as string) ) ddl2.items = theClassesNames --Set some default values if (OS3D_iniFunctions.OS3D_ExistIniFile()) then ( try ( OS3D_LoadIniSettings ExportObj ) catch ( print "could not load ini file properly, resetting and creating a new one" OS3D_iniFunctions.OS3D_RemoveIniFile() ) ) else ( OS3D_createDefaultSettings() --OS3D_LoadIniSettings ExportObj ) --edtFrameRange.text = "1-10,13,16,30-35" --edtPrefixText.text = "MyPrefixText" ) on ExportObj close do ( OS3D_SaveIniSettings ExportObj ) on edtPrefixText changed val do ( StatusText() ) on btnStartExport pressed do ( OS3D_SaveIniSettings ExportObj theClasses = exporterPlugin.classes if outPath == undefined then ( outPath = "" outPath = getSavePath initialDir:outpath ) if outPath != undefined then ( selArray = selection as array sceneObjs =#() TimeRange = OS3DGetRanges edtFrameRange.text spnFrameByStep.value if (animationRange.start as float) > TimeRange[1] then ( animationRange= interval TimeRange[1] animationRange.end ) if (animationRange.end ) < TimeRange[TimeRange.count] then ( animationRange= interval animationRange.start TimeRange[TimeRange.count] ) timeDisplayMode = #frameTicks sceneObjs = #() for item in selArray do ( if (isGroupMember item) or (isGroupHead item) then ( temp = (OS3D_isGroupMasterHead item) append sceneObjs temp ) else --just a single obj ( print item.name append sceneObjs #(item) ) ) sceneobjs = makeUniqueArray sceneobjs ic = 0 for i = 1 to sceneObjs.count do ( --oname = (if chkAddPrefix.state then edtPrefixText.text else sceneObjs[i].name) if sceneObjs[i].count != 0 then ( ic += 1 if ic == 1 then --the first object in the selection will display the promt to set the settings... ( showPrompt = true for f in TimeRange do ( if showPrompt then ( select sceneObjs[i] ExpObjName = OS3D_item_name sceneObjs[i] if ExpobjName == "" then ExpobjName = sceneObjs[i][1].name NewName = OS3DFileName outPath ExpobjName chkAddPrefix.state edtPrefixText.text chkAddZeros.state spnNrOfDigits.value f spnOffset.value chkAddFrame.state slidertime = (f as time) OS3DDoExport true true NewName chkSingleMesh.checked slidertime showPrompt = false )else ( select sceneObjs[i] ExpObjName = OS3D_item_name sceneObjs[i] if ExpobjName == "" then ExpobjName = sceneObjs[i][1].name NewName = OS3DFileName outPath ExpobjName chkAddPrefix.state edtPrefixText.text chkAddZeros.state spnNrOfDigits.value f spnOffset.value chkAddFrame.state slidertime = (f as time) OS3DDoExport true false NewName chkSingleMesh.checked slidertime ) ) ) if ic > 1 then --for every obj exept the first try to skip the prompt... ( for f in TimeRange do ( select sceneObjs[i] ExpObjName = OS3D_item_name sceneObjs[i] if ExpobjName == "" then ExpobjName = sceneObjs[i][1].name NewName = OS3DFileName outPath ExpObjName chkAddPrefix.state edtPrefixText.text chkAddZeros.state spnNrOfDigits.value f spnOffset.value chkAddFrame.state slidertime = (f as time) OS3DDoExport true false NewName chkSingleMesh.checked slidertime ) ) ) ) --select sceneObjs timeDisplayMode = #frames ) else ( messagebox "No output path selected" ) )---------end export on chkAddPrefix changed theState do ( if theState then edtPrefixText.readOnly = false else edtPrefixText.readOnly = true StatusText() OS3D_SaveIniSettings ExportObj ) on chkDebug changed state do ( print ("debug is " + state as string) debug = state ) on spnNrOfDigits changed val do ( StatusText() OS3D_SaveIniSettings ExportObj ) on chkAddZeros changed theState do ( StatusText() OS3D_SaveIniSettings ExportObj ) on edtFrameRange changed val do ( StatusText() OS3D_SaveIniSettings ExportObj ) on spnFrameByStep changed val do ( StatusText() OS3D_SaveIniSettings ExportObj ) on spnOffset changed val do ( StatusText() OS3D_SaveIniSettings ExportObj ) on chkAddFrame changed val do ( StatusText() OS3D_SaveIniSettings ExportObj ) on btn2 pressed do ( if outPath == undefined then ( outPath = "" outPath = getSavePath() ) else ( outPath = (getSavePath initialDir:outpath) ) if outPath != undefined then ( btn2.caption = outPath ) else ( btn2.caption = "click to set output folder" ) StatusText() OS3D_SaveIniSettings ExportObj ) on btnResetIniFile pressed do ( OS3D_createDefaultSettings() OS3D_LoadIniSettings ExportObj ) on btnSelectVisibleObjects pressed do ( select (for o in geometry where (canConvertTo o mesh) and o.isHidden != true collect o) ) ) createdialog ExportObj