macroScript ConcatMatrialLibraries category:"Usefull:Tools" tooltip:"Concat Matrial Libraries" buttontext:"Concat Matrial Libraries" --silentErrors:true ( global ConcatMatrialLibraries global SearchFolder = "" global SaveFile = "" global MaterialsIndex = #() global DefaultMatLibFolder = PathConfig.convertPathToAbsolute "$maps/" global AllMatFilesPath = #() global AllMatFilesName = #() Global MaterialCollection = #() global TotalMatLibs = 0 clearListener() rollout ConcatMatrialLibraries "Concat Matrial Libraries" width:208 height:288 ( button FolderBtn "Material Library Path" pos:[8,8] width:192 height:16 label FolderLbl "" pos:[8,32] width:192 height:32 button SaveFileBtn "Select SaveFile" pos:[8,192] width:192 height:16 listbox FileList "" pos:[8,72] width:192 height:8 label SaveFileLbl "" pos:[8,216] width:192 height:32 button MainBtn "Collect Materials to File" pos:[8,256] width:192 height:24 enabled:false fn SrchFiles Folder FileMask = ( Directories = #() AllMatFilesPath = #() AllMatFilesName = #() FileList.Items = #() Append Directories Folder while Directories.Count > 0 do ( SrchFile = GetFiles (PathConfig.AppendPath Directories[1] FileMask) for CurFile in SrchFile do ( Append AllMatFilesPath CurFile Append AllMatFilesName (filenamefrompath(CurFile)) ) SrchDir = GetDirectories (PathConfig.AppendPath directories[1] "*") for CurDir in SrchDir do Append Directories CurDir DeleteItem Directories 1 ) return AllMatFilesPath ) fn ReadyState = ( MainBtn.Enabled = ((SaveFile != undefined) and (SaveFile != "") and (TotalMatLibs>0)) ) on FolderBtn pressed do ( SearchFolder = "" TempFolder = "" TempFolder = (GetSavePath caption:"Select Material Library" initialDir:DefaultMatLibFolder) if TempFolder != undefined then if DoesFileExist(TempFolder) then ( SearchPath = TempFolder TempFolder = undefined FolderLbl.Text = PathConfig.AppendPath SearchPath "*.mat" AllMatFilesPath = SrchFiles SearchPath "*.mat" TotalMatLibs = AllMatFilesPath.Count print TotalMatLibs if TotalMatLibs > 0 then FileList.Items = AllMatFilesName ) ReadyState() ) on SaveFileBtn pressed do ( TempFile = (GetSaveFileName caption:"Select Material Library" types:"Material library(*.mat)|*.mat") if (TempFile != undefined) then ( SaveFile = TempFile TempFile = undefined SaveFileLbl.text = SaveFile ) ReadyState() ) fn compareFN F1 F2 = ( d = (F1.name > F2.name) case d of ( true: 1 false: -1 default: 0 ) ) on MainBtn pressed do ( SaveLib = materialLibrary() print TotalMatLibs for CurInd = 1 to TotalMatLibs do ( ProcLib = LoadTempMaterialLibrary AllMatFilesPath[CurInd] TotalProcLibMat = ProcLib.Count for CurInd = 1 to TotalProcLibMat do ( CurMat = ProcLib[CurInd] if SuperClassOf CurMat == material then ( Append MaterialCollection CurMat ) ) ) TotalMaterials = MaterialCollection.count qsort MaterialCollection compareFN for i = 1 to TotalMaterials do Append SaveLib MaterialCollection[i] SaveTempMaterialLibrary SaveLib SaveFile /*for i = 1 to TotalMaterials-1 do for j = i+1 to TotalMaterials do ( format "(% = %): % \n" MaterialCollection[i].name MaterialCollection[j].name (MaterialCollection[i].name == MaterialCollection[j].name) )*/ ) ) if ConcatMatrialLibraries != Undefined then DestroyDialog ConcatMatrialLibraries CreateDialog ConcatMatrialLibraries )