/* Written by David Holmedal www.davidholmedal.com davidholmedal@gmail.com Please do not redistribute, but instead refer to my website. */ macroscript objImportExportExtended category:"Benzie" buttonText:"Obj Imp/Exp" toolTip:"Import Obj with transform, click to import, shift click to export" --## START MACRO ##-- ( --FUNCTIONS --read tm matrix fn readTMmatrix theFile =( seek thefile 0 local theTM = matrix3 1 --identity matrix local theLine = readline theFile local testStr = substring theLine 1 12 if testStr == "# TMatrix = " do( theTM = execute (substring theLine 13 theLine.count) ) return theTM )--end fn --move pivot to transform fn movePivot theObj theTransform =( with redraw off( local b = box() b.name = theObj.name converttopoly b polyop.deleteVerts b #all b.transform = theTransform b.editablepoly.attach theObj b select b ) )--end fn --write to top fn combineFiles topFile bottomFile =( local tfile = openFile topFile mode:"a" local bfile = openFile bottomFile mode:"r" while not (eof bFile) do( theLine = (readLine bFile) as string format (theLine + "\n") to:tFile ) close tfile close bfile )--end fn if keyboard.shiftpressed then( --## EXPORT AND STORE PIVOT ##-- local theObj = selection[1] local theTM = theObj.transform as string local theFileName = \ getSaveFileName caption:"Choose Obj file to open" \ types:"*.obj"\ historyCategory:"Obj Extended" if (getFilenameType theFileName) == "" then( theFileName = theFileName +".obj" )else if (getFilenameType theFileName) != ".obj" then( theFilename = (getFilenamePath theFileName) ) exportFile theFileName selectedOnly:true #noPrompt --using: local tempFileName = (getFilenamePath theFileName) + "temp_" + (filenameFromPath theFileName) theFile = createFile tempFileName close theFile theFile = openFile tempFileName mode:"a" format ("# TMatrix = " + theTM + "\n") to:theFile close theFile combineFiles tempFileName theFileName deleteFile theFileName format "thefilename after delete: %\n" theFileName format "thetempfilename after delete: %\n" tempFileName if (renameFile tempFileName theFileName) then( )else( print "File Renaming failed" ) )else( --## IMPORT AND MOVE PIVOT ##-- ( local theFileName = \ getOpenFileName caption:"Choose Obj file to open" \ types:"*.obj"\ historyCategory:"Obj Extended" if theFileName != undefined do( importFile theFileName #noPrompt --using: local impObj = selection[1] local theName = filenameFromPath theFileName if (matchPattern theName pattern:"_lvl" ignoreCase:true)do( --checking to see, if obj isn't base subd level local tempStr = (filterString theName "_lvl")[1] theFileName = (getFilenamePath theFileName) + tempStr + ".obj" ) format "thefilename: %\n" --reading TM matrix from file local theFile = openFile theFileName local tm = readTMmatrix theTMFile close theFile format "the TM: %\n" tm movePivot impObj tm ) ) )--end if shiftpressed )--## END MACRO ##--