View Single Post
Old 09-08-2019, 11:32 AM   #12
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,832
Default

Quote:
Originally Posted by Arthur McArthur View Post
I need a script that inserts a FX to the selected track(s) and moves those FX windows to one set of x/y screen coordinates. The FX name and coordinates should be hard-coded into the script (no dialogs).
Try this:
Code:
FX = "ReaEQ"
x  = 100
y  = 100
spacing  = 20 -- Added to x and y for each FX

reaper.Undo_BeginBlock2(0)

-- Create a table with all currently open windows, so that newly opened FX windows can be distinguished
a = reaper.new_array({}, 1000)
reaper.JS_Window_ArrayAllTop(a)
t = a.table()
t1 = {}
for i = 1, #t do
    t1[t[i]] = true
end

-- Now add FX (if not already in track chain) and open FX window
for t = 0, reaper.CountSelectedTracks(0)-1 do
    track = reaper.GetSelectedTrack(0, t)
    index = reaper.TrackFX_AddByName(track, FX, false, 1) -- 1=only add if not yet already in chain. -1 to always add
    reaper.TrackFX_Show(track, index, 3)
end

-- Find all newly opened windows, and move them to x,y coordinates
a.resize(0)
reaper.JS_Window_ArrayAllTop(a)
t2 = a.table()
for i = 1, #t2 do
    address = t2[i]
    if not t1[address] then 
        hwnd = reaper.JS_Window_HandleFromAddress(address)
        if reaper.ValidatePtr(hwnd, "HWND") 
        --and reaper.JS_Window_GetTitle(hwnd):match(FX) -- This line might be necessary, but may also cause problems for non-English Unicode names
        then
            reaper.JS_Window_Move(hwnd, x, y)
            x, y = x+spacing, y+spacing
        end
    end
end

reaper.Undo_EndBlock2(0, "Add FX: "..FX, 0)
EDIT: Fixed a bug.

Last edited by juliansader; 09-08-2019 at 11:27 PM.
juliansader is online now   Reply With Quote