fromFrame and toFrame in SaveFileCopyAs does not seem to work in for loop

Hi everyone,

I am very new to LUA and scripting for Aseprite and I can’t get the SaveFileCopyAs function to work.

Here is my code:

local nameList = {"firstName", "secondName", "thirdName"}

for i=1, #(app.sprite.frames) do
	app.command.SaveFileCopyAs {		
		filename= nameList[i],
		fromFrame = i-1,
		toFrame = i-1

Basically, it should cycle through every frame and then save that frame with a specified exportName (e.g., “firstName”, “secondName”, etc.).

The for loop diligently goes through the code for the amount of frames in the active sprite.
The first frame usually gets exported correctly. However, sometimes I get the “Saving an animation as a sequence of static images”-Alert. The second frame always triggers this prompt. When clicking no, the export stops (which is fine), when clicking yes, the second export will be “secondName1” and “secondName2” with frame 1 and frame 2 respectively.

I believe, the fromFrame and toFrame arguments somehow do not quite work. I tried using toFrame = i+1 in case it is exclusive, but then I get out of bounds errors.

Any idea how I correctly use these arguments? I am starting to think this might be a bug.

Happy for any tips or workarounds.
Thanks in advance!

On a sidenote: my original code had fromFrame=i, toFrame=i since i assumed the frame number checked by SaveFileCopyAs was the same as the number in “app.range.frames”, but I think wherever array/list/whatever SaveFileCopyAs looks starts at 0, not 1. It is a bit confusing :sweat_smile:

I kept tinkering with this and the behaviour of the whole thing becomes more puzzling to me:

I added the ability to only save a selected range of frames.

If I select a single frame, this code export this frame correctly. If I select more than one frame, the first sometimes gets exported correctly, sometimes the program wants to export all frames. Starting with the second iteration of the for loop, the program wants to export every frame every time.

local nameList = {“firstName”, “secondName”, “thirdName”}
local frameRange = app.range.frames

for i=1, #(frameRange) do
   -- just so I can be sure the same frame is used for fromFrame and toFrame:
    local exportFrame = frameRange[i]

    app.command.SaveFileCopyAs {
      filename= nameList[i],
      fromFrame = exportFrame ,
      toFrame = exportFrame


I did check that “frameRange[i]” iterates properly and it seems to do so.
I both tried giving frames and framenumbers to the command, but nothing seems to help.