Created
February 14, 2022 17:32
-
-
Save X-Raym/eb15030ab75fd0bafceab0d435d07d84 to your computer and use it in GitHub Desktop.
repeat action by sets of 100 items max in selection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
* ReaScript Name: Repeat action by sets of 100 items max in selection | |
* Screenshot: https://i.imgur.com/nQsH3mL.gif | |
* Author: X-Raym | |
* Author URI: | |
* Repository: | |
* Repository URI: | |
* Licence: GPL v3 | |
* Forum Thread: | |
* Forum Thread URI: | |
* REAPER: 5.0 | |
* Version: 1.0 | |
--]] | |
-- USER CONFIG AREA ----------------------------------------------------------- | |
console = true -- true/false: display debug messages in the console | |
action_id = 65535 -- integer or string like "_RS58e79379a72978b5be7ee39118af7b78b949dd08" | |
undo_text = "My action" | |
------------------------------------------------------- END OF USER CONFIG AREA | |
-- UTILITIES ------------------------------------------------------------- | |
-- Save item selection | |
function SaveSelectedItems(t) | |
local t = t or {} | |
for i = 0, reaper.CountSelectedMediaItems(0)-1 do | |
t[i+1] = reaper.GetSelectedMediaItem(0, i) | |
end | |
return t | |
end | |
function RestoreSelectedItems( items ) | |
reaper.SelectAllMediaItems(0, false) | |
for i, item in ipairs( items ) do | |
reaper.SetMediaItemSelected( item, true ) | |
end | |
end | |
-- Display a message in the console for debugging | |
function Msg(value) | |
if console then | |
reaper.ShowConsoleMsg(tostring(value) .. "\n") | |
end | |
end | |
function Main_OnCommand( val ) | |
if not tonumber(val) then | |
val = reaper.NamedCommandLookup(val) | |
end | |
reaper.Main_OnCommand( val, 0 ) | |
end | |
--------------------------------------------------------- END OF UTILITIES | |
-- Main function | |
function Main() | |
sets = 0 | |
reaper.SelectAllMediaItems(0, false) | |
for i, item in ipairs(init_sel_items) do | |
reaper.SetMediaItemSelected( item, true ) | |
if i % 100 == 0 or i == #init_sel_items then | |
Main_OnCommand( action_id ) | |
reaper.ShowMessageBox("Items " .. sets * 100 .. " - " .. i , "Info", 0) | |
reaper.SelectAllMediaItems(0, false) | |
reaper.UpdateArrange() | |
sets = sets + 1 | |
end | |
end | |
end | |
-- INIT | |
function Init() | |
-- See if there is items selected | |
count_sel_items = reaper.CountSelectedMediaItems(0) | |
if count_sel_items == 0 then return false end | |
--reaper.PreventUIRefresh(1) | |
reaper.Undo_BeginBlock() | |
init_sel_items = SaveSelectedItems() | |
Main() | |
RestoreSelectedItems(init_sel_items) | |
reaper.Undo_EndBlock(undo_text, -1) | |
reaper.UpdateArrange() | |
--reaper.PreventUIRefresh(-1) | |
end | |
if not preset_file_init then | |
Init() | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment