My only other thought is to check if the fx index is valid first, if not then close the chain window or whatever,...
Code:
...
deleteChain() -- to make sure the chain is clean
fx_index = 0 -- the fx index were interested in.
if fx_index > reaper.TrackFX_GetCount(track)-1 then
msg('FX index is out of range, close chain if open')
reaper.TrackFX_Show(track, fx_index, 0) -- =0 for hidechain
else
if not reaper.TrackFX_GetOpen(track, fx_index) then
msg ("1 - TrackFX is closed so it opens")
reaper.TrackFX_SetOpen(track, fx_index, true)
else
msg ("2 - TrackFX is opened so it closes")
reaper.TrackFX_SetOpen(track, fx_index, false)
end
end