I wrote a script that's supposed to expand the selected folders and collapse all others.
When I start it in the editor, compilation is fine but nothing happens !!!
Any idea ?
Code:
--[[
* ReaScript Name: Expand selected folders collapse others
* Author: BenF
* Licence: GPL v3
* REAPER: 5.0
* Extensions: None
* Credits: x-raym for the empty script
* Description: Automatically expands the selected folder(s) and collapse the others
* Instructions:
* Select the folder(s) you want to expand
--]]
--[[
Changelog:
* v0.01
]]
-- Console Message
function Msg(m)
reaper.ShowConsoleMsg(tostring(m).."\n")
end
--/////////////// MAIN ///////////////////
function MainFunction()
i = 1
tr = reaper.GetTrack(0, 0)
folder = 0
depth = 0
selected = 0
ret = false
reaper.Undo_BeginBlock() -- Begining of the undo block. Leave it at the top of your main function.
-- take a look at each track in project.
for i = 1, reaper.CountTracks(0) do
tr = reaper.GetTrack(0, i-1)
-- look if it's a folder
folder = reaper.GetMediaTrackInfo_Value(tr, "I_FOLDERDEPTH")
-- get its depth
depth = reaper.GetTrackDepth(tr)
-- look if it's selected
selected = reaper.GetMediaTrackInfo_Value(tr, "I_SELECTED")
-- is it a folder ?
if folder == 1 then
-- is it selected ?
if selected == 1 then
-- we expand it
ret = reaper.SetMediaTrackInfo_Value(tr, "I_FOLDERCOMPACT ", 0)
else
if depth == 0 then
-- we collapse it
ret = reaper.SetMediaTrackInfo_Value(tr, "I_FOLDERCOMPACT ", 2)
end
end
end
end
reaper.Undo_EndBlock("BenF_Expand Selected Folders Collapse Others", 0) -- End of the undo block. Leave it at the bottom of your main function.
end
--reaper.PreventUIRefresh(1) -- Prevent UI refreshing. Uncomment it only if the script works.
MainFunction() -- Execute your main function
--reaper.PreventUIRefresh(-1) -- Restore UI Refresh. Uncomment it only if the script works.
reaper.UpdateArrange() -- Update the arrangement (often needed)