Session error in LUA scripts on Ardour v7.3

I have just upgraded to Ardour 7.3.0 from v6.9 on Ubuntu.

The problem is that, some scripts which were working fine on v6.9, stopped working on v7.3.

I keep getting errors for Session object. Specifically for:
for route in Session:get_tracks ():iter () do

The error message is:
LuaException: [string "ardour {..."]:30: attempt to index a nil value (global 'Session')

How can I fix the problem? Any idea?

Here are the whole code:

ardour {
	["type"]    = "EditorAction",
	name        = "mb:SelectAllNextRegions",
	license     = "MIT",
	author      = "mb",
	description = [[Select all regions after selection.]]
}


function factory () return function ()


  -- local ok, ext = Editor:get_selection_extents (0, 0)
  local ok, ext = Editor:get_selection_extents(Temporal.timepos_t:zero(true), Temporal.timepos_t:zero(true))

local start_pos = 0;
if (ok) then
 print(ok)
 start_pos = ext[1]
--end_pos = ext[2]
--       print ("Selection Extents:", ext[1], ext[2])
 end
print("start_pos:", start_pos)


	local sl = ArdourUI.SelectionList () -- empty selection list

	local sel = Editor:get_selection () -- get current selection
	-- for each selected track/bus..
	for route in Session:get_tracks ():iter () do
		-- consider only tracks
		local track = route:to_track ()
		if track:isnil() then
			goto continue
		end


		-- iterate over all regions of the given track
		for region in track:playlist():region_list():iter() do
print(region:name(), region:position());
			if (region:position () < start_pos) then
				-- skip regions before the start point.
			else
				-- get RegionView (GUI object to be selected)
				local rv = Editor:regionview_from_region (region)
				-- add it to the list of Objects to be selected
				sl:push_back (rv);
			end
		end
		::continue::
	end

	-- set/replace current selection in the editor
	Editor:set_selection (sl, ArdourUI.SelectionOp.Set);
end end

Time representation has changed in Ardour7 (tech details: https://ardour.org/timing.html)

change

to

local start_pos = Temporal.timepos_t (0)

Unfortunately I am still keep getting the same error message:

LuaException: [string “ardour {…”]:30: attempt to index a nil value (global ‘Session’)

I’ve just tested it here in Menu > Window > Scripting and it works after changing start_pos.

Correctly does what it describes. by default select all regions, or otherwise only those after the selected one.

Is a session open when you run the script? That would be the only explanation I have why Session could be nil.

1 Like

It’s interesting… I had opened the script editor window from Edit > Lua Scripts > Script Manager…

But it started to work correctly after following your suggestion: Menu > Window > Scripting

Thank you so much! :+1:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.