top of page
- Script Code -

dofile(reaper.AZ_GetLuaInitPath())

require("reaper_AZSTOKE_BRONZE")

require("reaper_AZSTOKE_SILVER")

require("reaper_AZSTOKE_GOLD")


retval, inputList = reaper.AZ_GetUserInputList("", 2, "Source Path,Excel Path", ",")


if retval then


    sourceParentPath = inputList[1]

    

    excelPath = inputList[2]

    

    track = reaper.AZ_InsertTrackSearchUniqueOnly(0, "work")

    

    sourcePathList = reaper.AZ_GetFilePathList(sourceParentPath, "wav")

    

    items = reaper.AZ_InsertMediaItems(track, sourcePathList, 0, 1)

    

    excel = reaper.AZ_Excel_OpenFile(excelPath)

    

    worksheet = reaper.AZ_Excel_OpenWorksheet(excel, "items")

    

    for i, item in pairs(items)do

    

      itemName = reaper.AZ_GetMediaItemName(item)

      

      itemLength = reaper.AZ_GetMediaItemLength(item)

    

      searchResult = reaper.AZ_Excel_SearchRowsInWorksheet(worksheet, itemName, "A")

      

      resultRow = ""

      

      for k, v in pairs(searchResult["Cells"]) do

      

          resultRow = k

      end

      

      if resultRow == "" then

      

          searchResult = reaper.AZ_Excel_SearchRowsInWorksheet(worksheet, ".+", "A", ",A", true)

          

          newRow = 1

          

          for k, v in pairs(searchResult["Cells"]) do newRow = newRow + 1 end

          

          reaper.AZ_Excel_SetCellValue_ByNumber(worksheet, newRow, 1, itemName)

          

          reaper.AZ_Excel_SetCellValue_ByNumber(worksheet, newRow, 2, itemLength) 

          

      else

      

          cell = "B" .. resultRow

          

          reaper.AZ_Excel_SetCellValue(worksheet, cell, itemLength) 

      end

      

    end

    

    reaper.AZ_Excel_SaveDocument(excel)

    

    reaper.AZ_Excel_CloseFile(excel)

  

end

- Warm Up -

  • Prepare an Excel file

  • Prepare the audio files to import

- Script Detail -

dofile(reaper.AZ_GetLuaInitPath())

require("reaper_AZSTOKE_BRONZE")

require("reaper_AZSTOKE_SILVER")

require("reaper_AZSTOKE_GOLD")


・Import RIGDOCKS


retval, inputList = reaper.AZ_GetUserInputList("", 2, "Source Path,Excel Path", ",")


・Prompt for the required input


if retval then


    sourceParentPath = inputList[1]

    

・Get the parent folder path of the audio files from the input values


    excelPath = inputList[2]


・Get the Excel file path from the input values


    track = reaper.AZ_InsertTrackSearchUniqueOnly(0, "work")

    

・Create a track named "work"


    sourcePathList = reaper.AZ_GetFilePathList(sourceParentPath, "wav")

    

・Get all audio file paths under the parent folder


    items = reaper.AZ_InsertMediaItems(track, sourcePathList, 0, 1)

    

・Insert the audio files into the "work" track


    excel = reaper.AZ_Excel_OpenFile(excelPath)

    

・Open the Excel file


    worksheet = reaper.AZ_Excel_OpenWorksheet(excel, "items")

    

・Open the "items" worksheet of the Excel file


    for i, item in pairs(items)do

    

      itemName = reaper.AZ_GetMediaItemName(item)

      

      itemLength = reaper.AZ_GetMediaItemLength(item)

    

・Get the media item name and length


      searchResult = reaper.AZ_Excel_SearchRowsInWorksheet(worksheet, itemName, "A")

    

・Search whether the worksheet has a row corresponding to the media item name


      resultRow = ""

      

      for k, v in pairs(searchResult["Cells"]) do

      

          resultRow = k

      end

    

・Get the row number of the search result


      if resultRow == "" then

    

・No row number in the search result → if there is no corresponding row


          searchResult = reaper.AZ_Excel_SearchRowsInWorksheet(worksheet, ".+", "A", ",A", true)

    

・Get rows where column A is not empty


          newRow = 1

          

          for k, v in pairs(searchResult["Cells"]) do newRow = newRow + 1 end

    

・Get the row numbers of rows where column A is empty


          reaper.AZ_Excel_SetCellValue_ByNumber(worksheet, newRow, 1, itemName)

          

          reaper.AZ_Excel_SetCellValue_ByNumber(worksheet, newRow, 2, itemLength) 

    

・Write the media item name and length as a new row


      else

    

・If there is a corresponding row


          cell = "B" .. resultRow

          

          reaper.AZ_Excel_SetCellValue(worksheet, cell, itemLength) 

    

・Write the length in column B


      end

      

    end

    

    reaper.AZ_Excel_SaveDocument(excel)

    

・Save the Excel file


    reaper.AZ_Excel_CloseFile(excel)

    

・Close the Excel file


end

- API LINK -
- API LINK -

Excel

AZSTOKE_Excel_InsertLength_1

Import audio files into Reaper and record their lengths in Excel

01_BRONZE_ss_edited.png
01_SILVER_edited_edited.png
03_GOLD_edited_edited.png
bottom of page