Simple export tags as png sequence script - Needs help!

Hi!

I am trying to write a script that exports each tag as a PNG sequence. A tag named “walkR” should export files “walkR_0.png”, “walkR_1.png”, “walkR_2.png” and so on…

Here’s my script so far:

-- Exit if no active sprite
local spr = app.activeSprite
if not spr then return print('No active sprite') end

-- Export each tag to a separate PNG sequence
local path,title = spr.filename:match("^(.+[/\\])(.-).([^.]*)$")

for i, tag in ipairs(spr.tags) do
  app.command.SaveFile {
  	ui=false,
  	filename=path .. tag.name .. "_0.png",
  	filenameFormat='{path}/{tag}_{tagFrame}.{extension}',
  	tag=tag.name,
  	fromFrame=tag.fromFrame,
  	toFrame=tag.toFrame,
  }
end

Problem is, no files are output! Does anyone know what could be the issue?

Thanks!

I got it to save by changing

app.command.SaveFile

into

app.command.SaveFileAs

But the save command does not respect the tag, fromFrame or toFrame parameters, it saves every single frame in the file - and not just the frames that belong to the specific tags. Anyone know what could be causing this?

My bad! I was using an older version of Aseprite. Once I updated to the latest rc, the script works fine.

Here is the current version of the script. Maybe someone else will find this useful.

The script will hide any layers prefixed by “!” before exporting, and it will export to a subfolder named “export” below the project file.

-----------------------------------------------------------------
--
--	Simple script to export tags as PNG sequences
--
-----------------------------------------------------------------


-- Exit if no active sprite
local spr = app.activeSprite
if not spr then return print('No active sprite') end

-- Hide layers prefixed by '!'
hiddenLayers = {}

for i, layer in ipairs(spr.layers) do
	if layer.name:find('!', 1, true) == 1 and layer.isVisible == true then
		table.insert(hiddenLayers, layer)
		layer.isVisible = false
	end
end

-- Export each tag to a separate PNG sequence
local path,title = spr.filename:match("^(.+[/\\])(.-).([^.]*)$")
for i, tag in ipairs(spr.tags) do
  --print ('Exporting tag ' .. tag.name .. '_0 as PNG sequence')
  app.command.SaveFileCopyAs {
  	useUI=false,
  	filename=path .. "export/" .. tag.name .. "_0.png",
  	tag=tag.name,
  }
end

-- Unhide layers previously hidden
for i, hidden in ipairs(hiddenLayers) do
	hidden.isVisible = true
end
2 Likes

Your post was very useful to me. Thank you! :smile: