Old 08-20-2018, 09:00 AM   #1
benf
Human being with feelings
 
benf's Avatar
 
Join Date: Oct 2008
Location: France
Posts: 3,700
Default Help on a lua script

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)
__________________
Ma Zique
Mes Partoches
benf is offline   Reply With Quote
Old 08-20-2018, 09:31 AM   #2
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

"I_FOLDERCOMPACT " should be "I_FOLDERCOMPACT".

(There's a whitespace at the end)
spk77 is offline   Reply With Quote
Old 08-20-2018, 10:25 AM   #3
benf
Human being with feelings
 
benf's Avatar
 
Join Date: Oct 2008
Location: France
Posts: 3,700
Default

Yes. Thanks !
How didn't I see that ?!!!
__________________
Ma Zique
Mes Partoches
benf is offline   Reply With Quote
Old 08-20-2018, 10:50 AM   #4
spk77
Human being with feelings
 
Join Date: Aug 2012
Location: Finland
Posts: 2,668
Default

It's sometimes difficult to catch those kind of typos
spk77 is offline   Reply With Quote
Old 08-20-2018, 12:26 PM   #5
Thonex
Human being with feelings
 
Join Date: May 2018
Location: Los Angeles
Posts: 1,721
Default

Quote:
Originally Posted by spk77 View Post
It's sometimes difficult to catch those kind of typos
I'm the worst with finding those types of syntax errors. Nice catch spk777!
__________________
Cheers... Andrew K
Reaper v6.80+dev0621 - June 21 2023 • Catalina • Mac Mini 2020 6 core i7 • 64GB RAM • OS: Catalina • 4K monitor • RME RayDAT card with Sync Card and extended Light Pipe.
Thonex is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.