Just ended up here nearly a year later trying to solve the same issue again.
Thanks SPK77, that did the trick.
Code:
function ClearExistingSection()
-- get item
local item = reaper.GetSelectedMediaItem(0, 0)
-- get item length
if item ~= nil then
local itemlen = reaper.GetMediaItemInfo_Value( item, "D_LENGTH" )
-- get take
local take = reaper.GetActiveTake(item)
-- get source file
if take ~= nil then
src = reaper.GetMediaItemTake_Source( take )
-- get section info
local retval, offs, len, rev = reaper.PCM_Source_GetSectionInfo( src )
end
end
if retval == true then -- If section exists turn section off
reaper.Main_OnCommand(40547,1,0)
end
end
I needed to make sure that any previously existing sections were removed before adding a new one.
One thing to note, is that using reaper.Main_OnCommand(40547,1,0) twice in a row to disable the old and enable the new section didn't work. The effect would be that the section was removed, but a new one not added, presumably because the execution was too fast.
Moving the second reaper.Main_OnCommand(40547,1,0) to outside the function solved the issue.
Seems like a slight bug with the command.