I’m trying to set the default render path, for each individual project. I’m using a Lua script with API calls to achieve this, but I’m having problems making it work.
I begin by calling up a ‘browse for folder’ dialogue box, to get the path address to desired target folder and store that path in a String variable:
Code:
local numberreturn, pathreturn = reaper.JS_Dialog_BrowseForFolder("Caption", "C:/")
The path address gets returned into “pathreturn” string. I then use a function to insert this address into Reaper’s RENDER_FILE parameter:
Code:
function InsertPath()
reaper.GetSetProjectInfo_String(0, 'RENDER_FILE', pathreturn, true)
end
The address path does get stored into the "pathreturn" variable. I know this for certain. And I get no error message from the function either.
But when I open the “Render Project to disk ..” dialogue (pic below), and look at the “Directory” text field, it is empty. There is no path to the standard folder for this project inserted.
But there is another script like this, which does roughly the same thing. It’s written by renown Reaper user MPL (thanks, man). His script is made to set the default render path to the Windows desktop address (C:\Users\Username\Desktop).
When I run his script, it works. When I open the Render Project do disk, and look at the Directory field, it says “C:\Users\Username\Desktop” there. This is what I wanted to achieve for myself.
MPL’s script looks like this:
Code:
function GetDesktopPath()
local desktopPath = os.getenv("appdata")
local appDataStart = string.find( desktopPath, "AppData" )
if( appDataStart ) then
desktopPath = string.sub( desktopPath, 1, appDataStart-1 )
desktopPath = desktopPath .. "Desktop\"
end
return true, desktopPath
end
function main()
local ret, desktopPath = GetDesktopPath()
if ret and GetOS():match('Win') then
reaper.GetSetProjectInfo_String(0, 'RENDER_FILE', desktopPath, true)
end
end
What makes MPL’s script successful in inserting the default render path, and my script unsuccessful in achieving this? I have much to learn about advanced Lua, but I can follow code reasonably well I think. Yet, I'm having problem to decode the magic factor here.
Looking at MPL’s code, it seems to me that MPL’s GetDesktopPath function is basically a search function which searches out the exact address to the desktop. And his main function is quite similar to mine, except for details like MPL employs a ‘Windows only’ condition test.
I am having problems seeing how I can learn from MPL’s good script, to make my own implementation as successful as his is. I’d love if someone could lend me a hand and walk me through that.
thanx
/C.