------------------------------------------------------------------------------ -- Re/Loader -- -- composition script for Fusion 5.0 -- -- This script reload all or specified loaders clips, with files it should -- find in specified dir, parent dir or dir at the same level (of specified dir) -- in that order. -- -- Version : 1.2 -- author : Alexandre Aillet (webmaster@F-oeni-X.com) -- Idea : Guillaume Jallot -- Created : September 2007 -- Updated : Febuary 2008 ------------------------------------------------------------------------------ ----------------------------------------------------------------------- ----------------------------- functions --------------------------- ----------------------------------------------------------------------- ----------------------------------------------------------------------- -- GetLoaderList function (useless since eyeon.GetLoaders -- exists, but just for training and fun) ----------------------------------------------------------------------- -- list all loaders in "comp" -- input : comp (string, name of the composition) -- output : loaderTable (table, list of all "comp" loader(s)) ----------------------------------------------------------------------- function GetLoaderList (comp) loaderTable = {} -- cycle on comp toollist for i, tool in comp:GetToolList() do -- tool is a loader? if tool:GetAttrs().TOOLS_RegID == "Loader" then table.insert(loaderTable, tool) end end return loaderTable end ----------------------------------------------------------------------- -- ClipCount function ----------------------------------------------------------------------- -- count loaderTable clip -- input : loaderTable (table, list of loader(s)) -- output : clipCount (integer, number of loaderTable clip(s)) ----------------------------------------------------------------------- function ClipCount (loaderTable) clipCount = 0 -- cycle on loaderTable list for i, ldr in loaderTable do -- cycle on loader clip list for j, clip in ldr:GetAttrs().TOOLST_Clip_Name do clipCount = clipCount + 1 end end return clipCount end ----------------------------------------------------------------------- -- dirToScan function ----------------------------------------------------------------------- -- scan all dir in "path" -- input : path (string, name of the path to scan) -- output : dirToScanTable (table, list of "path" parent dir -- and all its dir child) ----------------------------------------------------------------------- function dirToScan (path) -- list the entire dir, parent dir included dirToScanTable = {} -- insert path in first position table.insert(dirToScanTable, path) -- parent dir of path pathParentDir = string.gsub(path, "(.*\\).*\\", "%1") -- scan dir pathParentDirTable = readdir(pathParentDir .. "*.*") -- insert parent dir in second position table.insert(dirToScanTable, pathParentDirTable.Parent) for i = 1, table.getn(pathParentDirTable) do if pathParentDirTable[i].IsDir then childDir = (pathParentDirTable.Parent .. pathParentDirTable[i].Name .. "\\") if childDir ~= path then table.insert(dirToScanTable, childDir) end end end return dirToScanTable end ----------------------------------------------------------------------- -- Reload function ----------------------------------------------------------------------- -- change clipname for each element in "clipNameTable" -- if present in an element of DirTable" -- input : clipNameTable (table, list of file to find) -- DirTable (table, list of dir where to search each "clipNameTable" element) -- loaderTable (table, list of loader to reload -- loaderIndexTable(table, list of loader index -- clipIndexTable (table, list of clip index -- clipStartFrameTable (table, list of each "clipNameTable element" start frame) -- output : nill ----------------------------------------------------------------------- function Reload (clipNameTable, DirTable, loaderTable, loaderIndexTable, clipIndexTable, clipStartFrameTable) print("--------------------------------------------------------------------------------------\n") loaderReloaded = 0 --cycle on clipNameTable for i, clip in clipNameTable do j = 1 clipExists = false -- cycle on DirTable to search if file exists while j <= table.getn(DirTable) and not clipExists do if fileexists(DirTable[j]..clip) then clipExists = true clipDir = DirTable[j] end j = j + 1 end -- loader index of the current loader clip loaderIndex = loaderIndexTable[i] -- clip index of the current loader clip clipIndex = clipIndexTable[i] if clipExists then -- new file path clipPath = clipDir .. clip -- change it loaderTable[loaderIndex].Clip[clipStartFrameTable[i]] = clipPath -- print find and reloaded print(string.format("%-10s %-1s %-40s %-40s", loaderTable[loaderIndex]:GetAttrs().TOOLS_Name, ":", clip, "reloaded with ".. clipPath)) loaderReloaded = loaderReloaded + 1 else -- print not find print(string.format("%-10s %-1s %-40s %-40s", loaderTable[loaderIndex]:GetAttrs().TOOLS_Name, ":", clip, "file not found")) end end print("\n--------------------------------------------------------------------------------------\n") print(loaderReloaded .. "/" .. table.getn(clipNameTable) .." clip reloaded on " .. table.getn(loaderTable) .. " loader(s)\n") end ----------------------------------------------------------------------- ---------------------------- main script -------------------------- ----------------------------------------------------------------------- print("--------------------------------------------------------------------------------------") print("------------------------------------ Re/Loader -------------------------------------") print("--------------------------------------------------------------------------------------") -- get current open comp current_comp = fusion:GetCurrentComp() if not current_comp then print("no open composition") else -- list all loader in comp allLoaderTable = GetLoaderList(current_comp) if table.getn(allLoaderTable) == 0 then print("no loader in composition") else -- table of filename of clips( nbClip = ClipCount(allLoaderTable) if nbClip == 0 then print("no clip in composition") else -- table of filename of clips( allClipNameTable = {} -- table for the dropdown of the loader list control DropDownDlgLoaderTable = {} -- table for the dropdown of the option list control DropDownDlgOptionsTable = {"Reload selected loader(s)", "Reload all loaders"} -- table of loader index, in case of multiple clip loader allLoaderIndexTable = {} -- table of clip index, in case of multiple clip loader allClipIndexTable = {} -- table of clip start frame, in case of multiple clip loader allClipStartFrameTable = {} -- cycle on loader list for i, ldr in allLoaderTable do -- cycle on loader clip list for j, clip in ldr:GetAttrs().TOOLST_Clip_Name do -- extract the filename of the loader clip name clipName = string.gsub(clip, ".*\\(.+%..+)", "%1") --insert info in tables table.insert(allClipNameTable, clipName) table.insert(DropDownDlgLoaderTable, ldr:GetAttrs().TOOLS_Name .. " : " .. clipName) table.insert(allLoaderIndexTable, i) table.insert(allClipIndexTable, j) table.insert(allClipStartFrameTable, ldr:GetAttrs().TOOLNT_Clip_Start[j]) end end -- default clip path for dialog box (first clip path of the first loader found) dlgDefaultClipPath = string.gsub(allLoaderTable[1]:GetAttrs().TOOLST_Clip_Name[1],"(.*\\).+%..+", "%1") -- dialogbox for the loader new path dialogBox = current_comp:AskUser("Re/Loader", { {"dlgLoaderList", Name = "Select a clip", "Dropdown", Options = DropDownDlgLoaderTable, Default = 0}, {"dlgNewPath", Name = "Select a new path for selected clip", "PathBrowse", Default = dlgDefaultClipPath}, {"dlgOptionList", Name = "Reload option", "Dropdown", Options = DropDownDlgOptionsTable, Default = 1} }) -- action according to user response if not dialogBox then print("Cancel by user") else -- comp lock current_comp:Lock() -- dialogbox attibute gather loaderNewPath = dialogBox.dlgNewPath -- dir to scan for clip scanDirTable = dirToScan(loaderNewPath) if dialogBox.dlgOptionList == 0 then -- index table of selected loader, in allLoaderTable loaderSelTable = {} for i, loader in allLoaderTable do if loader:GetAttrs().TOOLB_Selected then table.insert(loaderSelTable, loader) end end if table.getn(loaderSelTable) == 0 then print("no loader selected") else -- filename table of all the clip of the selected loader loaderSelClipNameTable = {} -- index table of selected loader, in allLoaderTable loaderSelIndexTable = {} -- index table of clip of selected loader loaderSelClipIndexTable = {} -- table of start frame for all clip of selected loader loaderSelClipStartFrameTable = {} -- cycle on loader index table for i, loaderIndex in allLoaderIndexTable do for j, loaderSel in loaderSelTable do if allLoaderTable[loaderIndex] == loaderSel then --insert info in tables table.insert(loaderSelIndexTable, allLoaderIndexTable[i]) table.insert(loaderSelClipNameTable, allClipNameTable[i]) table.insert(loaderSelClipIndexTable, allClipIndexTable[i]) table.insert(loaderSelClipStartFrameTable, allClipStartFrameTable[i]) end end end Reload(loaderSelClipNameTable, scanDirTable, allLoaderTable, loaderSelIndexTable, loaderSelClipIndexTable, loaderSelClipStartFrameTable) end else Reload( allClipNameTable, scanDirTable, allLoaderTable, allLoaderIndexTable, allClipIndexTable, allClipStartFrameTable) end -- comp unlock current_comp:Unlock() end end end print("--------------------------------------------------------------------------------------\n") end