Old 10-23-2019, 11:05 AM   #1
divedive
Human being with feelings
 
Join Date: Feb 2012
Location: New York
Posts: 154
Default Confused why this simple script isn't working

--space selected items down the timeline
--select items, place cursor in desired position, run
--selected items are moved to that cursor position, with X seconds between them

function Msg(variable)
reaper.ShowConsoleMsg(tostring(variable).."\n")
end

numselitems = reaper.CountSelectedMediaItems(0)
--Msg(numselitems)
curpos = reaper.GetCursorPosition()
spacing = 5.00

if (numselitems > 1) then
for i = 0, numselitems-1,1 do
--Msg(i)
--Msg(i*spacing)
newpos = curpos + (i*spacing)
--Msg(newpos)
reaper.SetMediaItemInfo_Value( reaper.GetSelectedMediaItem(0, i ), "D_POSITION", newpos )
--Msg(reaper.SetMediaItemInfo_Value( reaper.GetSelectedMediaItem(0, i ), "D_POSITION", newpos ))
end
end






--
no errors, just results in this: (skips every other one)

thanks in advance
Attached Images
File Type: png Screen Shot 2019-10-23 at 2.03.56 PM.png (18.6 KB, 14 views)
divedive is offline   Reply With Quote
Old 10-23-2019, 11:25 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,420
Default

As soon as you move an item past any of the others, then you've changed the order of the selected media items. i.e. if you get item 0 and put it at the end, as in your image, then the original item 1 is now item 0, etc.

In this case, the easiest solution is to go through all of the selected items and put them in a table, then go through that table afterward to actually move them so your i values are consistent.

I can't test this right now, but try:
Code:
--space selected items down the timeline
--select items, place cursor in desired position, run
--selected items are moved to that cursor position, with X seconds between them

function Msg(variable)
  reaper.ShowConsoleMsg(tostring(variable).."\n")
end

numselitems = reaper.CountSelectedMediaItems(0)
--Msg(numselitems)
curpos = reaper.GetCursorPosition()
spacing = 5.00

selecteditems = {}
if (numselitems > 1) then
  for i = 0, numselitems-1,1 do
    --Msg(i)
    items.insert(reaper.GetSelectedMediaItem(0, i))
  end

  for i = 1, #selecteditems do
    --Msg((i - 1) * spacing)
    --Msg(newpos)
    newpos = curpos + ((i - 1) * spacing)
    reaper.SetMediaItemInfo_Value( items[i], "D_POSITION", newpos )
    --Msg(reaper.SetMediaItemInfo_Value( items[i], "D_POSITION", newpos ))
  end
end

(Also, you can use [code][/code] tags in posts to keep your code's formatting.
Lokasenna is online now   Reply With Quote
Old 10-23-2019, 11:32 AM   #3
divedive
Human being with feelings
 
Join Date: Feb 2012
Location: New York
Posts: 154
Default

Thank you!
divedive is offline   Reply With Quote
Old 10-23-2019, 12:00 PM   #4
divedive
Human being with feelings
 
Join Date: Feb 2012
Location: New York
Posts: 154
Default

Thanks again Lokasena! This worked.
Code:
--space selected items down the timeline
--select items, place cursor in desired position, run
--selected items are moved to that cursor position, with X seconds between them

function Msg(variable)
  reaper.ShowConsoleMsg(tostring(variable).."\n")
end

numselitems = reaper.CountSelectedMediaItems(0)
curpos = reaper.GetCursorPosition()
spacing = 10.00
itemTable = {}
if (numselitems > 1) then
  --fill table
  for i = 0, numselitems-1,1 do 
    itemTable[i] = reaper.GetSelectedMediaItem(0, i )
  end
  
  for i = 0, #itemTable,1 do    
    newpos = curpos + (i*spacing)
    reaper.SetMediaItemInfo_Value(itemTable[i], "D_POSITION", newpos )
  end
end
divedive 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 02:00 PM.


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